1

when application raises some exception, normally what is done is, exception is logged, displayed to user, and based on its severity, we continue to use app or close it.

In case of some exceptions, like

"Cannot perform this operation while dispatcher processing is suspended."

exception, where UI cannot display message to user, we need to use Dispatcher.BeginInvoke to asynchronously show the message to user. The problem with BeginInvoke is that it returns immediately and code continues to execute where from the point it showed message box. In cases where we require user input (like Yes / No dialogs).

So, how can we safely show the message box dialog, and still wait for the user resulting action, before we continue with code execution?

Goran
  • 5,932
  • 3
  • 32
  • 74

1 Answers1

0

If you use Invoke() instead of BeginInoke() your thread will not immediately return until the task has been completed, allowing you to ask for user input on how to proceed.

More information in this question

Community
  • 1
  • 1
Kevin DiTraglia
  • 24,092
  • 16
  • 88
  • 134
  • It is not possible to use Invoke when Dispatcher processing is suspended. – Goran Nov 01 '13 at 17:42
  • @Goran Ah I see, would it be possible to `BeginInvoke` not only the message box, but the remainder of the code you would like to run as well without requiring a lot of retooling of what you already have? – Kevin DiTraglia Nov 01 '13 at 17:50
  • Well, that would require complete code to be marked as async, since I can not really tell when an exception will happen (unhandled). :) – Goran Nov 01 '13 at 23:25