C# The Dispatcher is unable to request processing. This is often because the application has starved the Dispatcher's message pump

0

I've got quite a heavy WPF C# application, which I have been gradually moving over to MVVM.

After refactoring lots of the code to MVVM, now randomly when I am doing an intensive task, I get this:

System.InvalidOperationException: 'The Dispatcher is unable to request processing. This is often because the application has starved the Dispatcher's message pump.'

The stack trace is less than useful:

System.InvalidOperationException
  HResult=0x80131509
  Message=The Dispatcher is unable to request processing.  This is often because the application has starved the Dispatcher's message pump.
  Source=WindowsBase
  StackTrace:
   at System.Windows.Threading.Dispatcher.OnRequestProcessingFailure(String methodName)
   at System.Windows.Threading.Dispatcher.RequestForegroundProcessing()
   at System.Windows.Threading.Dispatcher.CriticalRequestProcessing(Boolean force)
   at System.Windows.Threading.Dispatcher.InvokeAsyncImpl(DispatcherOperation operation, CancellationToken cancellationToken)
   at System.Windows.Threading.Dispatcher.LegacyBeginInvokeImpl(DispatcherPriority priority, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndWrapper.Dispose(Boolean disposing, Boolean isHwndBeingDestroyed)
   at MS.Win32.HwndWrapper.Finalize()

I am really struggling to debug this, whats a good approach. What I am seeing is:

  • One of the major model components has its own thread (and update loop)
  • One of the update methods takes a tens of seconds
  • While this happens, my UI is fine, a major component is a 2D canvas with a minimap and I can zoom and move just fine doing that (think google maps)
  • I will get the above exception.

This happens even when I am not interacting with the UI. I just wanted to mention that I can zoom in and out while it crashes, which is odd, because that is a WPF component invoking on the dispatcher thread, and is clearly not having an issue getting its invocations serviced.

It always crashes quick.. like in under 10 seconds. It doesn't freeze for minutes then die.

What tools / how can I analyse what is holding up the message pump?

c#
wpf
multithreading
asked on Stack Overflow Apr 2, 2020 by CaptainMuffin • edited Apr 2, 2020 by Soheila Tarighi

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0