C# WPF - Cannot perform this operation while dispatcher processing is suspended -


i have contentdialoghost shows contentdialogs in grid.

the showdialog() method handles showing control in host, , returns contentdialogresult.

i want work windows dialogs, call showdialog(), code stops until user presses of dialog buttons.

here's implementation:

public contentdialogresult showdialog(contentdialog dialog)          {             // show host             this.visibility = visibility.visible;              _dialogresult = null;              if (_currentdialog == null)             {                 containergrid.children.add(dialog);                 _currentdialog = dialog;             }              dialog.primarybuttonclick += (s, ev) => { _dialogresult = contentdialogresult.primary; };             dialog.secondarybuttonclick += (s, ev) => { _dialogresult = contentdialogresult.secondary; };              while (_dialogresult == null)             {                 if (this.dispatcher.hasshutdownstarted ||                     this.dispatcher.hasshutdownfinished)                 {                     break;                 }                  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                 // throws exception below                 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                  this.dispatcher.invoke(                     dispatcherpriority.background,                     new threadstart(delegate { }));                 thread.sleep(20);             }              closedialog();              return _dialogresult.value;         } 

this wrapped in popups class, so:

public contentdialoghost.contentdialogresult showdialog(contentdialog dialog)         {             return mainwindow.contentdialoghost.showdialog(dialog);         } 

the exception occurs when calling showdialog() isvisiblechanged event, such here:

private void page_isvisiblechanged(object sender, dependencypropertychangedeventargs e)         {             if (this.isvisible)                 showsubviewdebugdialog(); // calls `showdialog()` above mentioned popups class         } 

what can fix or workaround issue?


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -