Running the really simple program below I’d expect ‘FILTER REACHED’ to execute when I click button1, but it doesn’t get hit (neither with nor without debugger attached). Any ideas … ?
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
new Thread(() =>
{
Dispatcher.CurrentDispatcher.UnhandledExceptionFilter += Dispatcher_UnhandledExceptionFilter;
doer();
}).Start();
}
void Dispatcher_UnhandledExceptionFilter(
object sender,
DispatcherUnhandledExceptionFilterEventArgs e)
{
MessageBox.Show("FILTER REACHED");
}
private void doer()
{
throw new NotImplementedException();
}
}
Thanks
According to the documentation on
Dispatcher(found here) it looks like the filter function will only be used if an uncaught exception is raised from theInvokeorBeginInvokemethods on theDispatcher.So what happens if you replace
doer()withDispatcher.CurrentDispatcher.Invoke(doer)(or similar) instead?