I am facing the same problem as described here:
Dispatcher throws InvalidOperationException on Messagebox.Show in Textchanged event
Although the solution works for me, I want to solve another problem: When I have no control on whether a message box is shown (external code), how do I gracefully recover from it?
If I set e.Handled = false
an exception propagates thought the rest of the code until it is caught somewhere else it making some trivial warning or informational message box mess up the rest of the application.
On the other hand if I set e.Handled = true
the dispatcher unhandled exception handler is called over and over again until I press "Ok" in the message box, at which point the application stays "frozen". Pressing pause, this is the call stack:
New: Pressing any key with the (window focused) after closing the MessageBox causes the application to unfreeze and continue execution as normal.
How do I cause the MessageBox to be closed without breaking my application? (even if the messagebox is not shown at all)
EDIT
As requested here is the exception stack trace.
Dispatcher processing has been suspended, but messages are still being processed.
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
More behaviour detected, see "new"