I have an application with 2 UI threads.
The Main UI thread has a Main window with a XamDockManager and a DocumentContentHost Control which contains a Pane.The second UI thread opens a Window with a ListBox, and starts a timer that inserts an item on ListBox every second.
When the main window pane's close button is clicked, a MessageBox is displayed in the RequestBeforeClose handler.
The problem appears when the second thread's window get focused while the main thread's MessageBox is displayed.
NOTE: If I show the MessageBox in other point of main thread there is not any problem, the problem seems appear when the MessageBox is shown from RequestBeforeClose handler.
The second thread gets suspended and every DispatcherOperationCallbacks (ListBox insertions) get queued until main thread's MessageBox is closed
I Attach a C# solution that reproduces this problem.
Any ideas how to fix this?
Thanks.
It seems like a problem in the WPF framework. Basically it will lock in the FindCommandBinding of the CommandManager while it is executing the command. As such when another thread gets into that method it too will lock on that method and essentially wait for the other thread to complete it's handling of that method which is where you are currently showing the message box. I've submitted the issue to MS. You should probably try to avoid any long running operations directly within those operations.
Hi Andrew, Thanks for your help. The attached program is a simulation of the identified problem, what I really want to do is ask for saving changes before closing the tab, so i would like display a modal dialog that locks the main thread, in order to cancel (or not) the tab closure.
could it be done in other way? if not, I will avoid that question in order to not locking the thread...
Thank you very much