1

I have overridden the OnUnhandledException in my bootstrapper, but in the following scenario it is not called:

public class Foo : IHandle<Bar> {
    public void Handle(Bar message) {
        // Do something that requires UI thread
    }

    public void DoSomething() {
        eventAggregator.PublishOnBackgroundThread(new Bar());
    }
}

When the handle method is called it will throw InvalidOperationException: The calling thread must be STA, because many UI components require this. because it is performed on the background thread instead of on the UI thread:

That exception is never caught by OnUnhandledException in my bootstrapper. Neither is it caught by the Application.DispatcherUnhandledException event handler.

How can I make a general exception handler that will also catch these types of exceptions, without having to implement try/catch everywhere?

TheHvidsten
  • 4,028
  • 3
  • 29
  • 62

2 Answers2

0

As per the Caliburn.Micro GitHub it appears this is a known problem, and is something that they're actively working on solving. You may wish to join the conversation over there and see if there are any stop-gap solutions for the time being.

Clint
  • 6,133
  • 2
  • 27
  • 48
0

It looks like this is a problem with background threads and WPF not making it to the event handler.

The linked question has a solution, but it's may be something we (Caliburn.Micro) can help with.

Nigel Sampson
  • 10,549
  • 1
  • 28
  • 31
  • Unfortunately `AppDomain.CurrentDomain.UnhandledException` does not get called either in this example. I would be very interested in seeing what you (Caliburn.Micro) could help with, though :) – TheHvidsten Jun 06 '17 at 11:13
  • Most likely it would trying to funnel all the various exception handlers to one place. However if this exception is just being swallowed by the thread pool then that won't help here sorry. – Nigel Sampson Jun 07 '17 at 21:25