An exception is raised if one tries to show a message box if the Dispatcher is suspended (Dispatcher.DisableProcessing() called).
InvalidOperationException: 'Dispatcher processing has been suspended' (see here).
Does anyone know how I can detect where the Dispatcher is suspended or not (so I know when to call BeginInvoke())?
Edit 1:
In reaction to the Application.DispatcherUnhandledException event I'm trying to show a MessageBox. However, if this unhandled Exception was thrown during DataBinding (i.e. ItemsControl.ItemsSource) the Dispatcher is suspended. Trying to show a MessageBox then fails. Always using Dispatcher.BeginInvoke() solves the problem, but I don't want to do that unless really necessary.
Edit 2:
Using Reflection to accomplish this works like this:
var dispatcherType = typeof(Dispatcher);
var countField = dispatcherType.GetField("_disableProcessingCount", BindingFlags.Instance | BindingFlags.NonPublic);
var count = (int)countField.GetValue(Dispatcher.CurrentDispatcher);
var suspended = count > 0;