Problems with global exception handlers for unhandled exceptions in multithreaded WPF

I have a program that, among other things, should be able to update the contents of the directory when the user reports it. The actual task does not matter much, but it is the easiest way to cause this problem that I know of. If I tell him to open a directory that does not exist, I get a โ€œraw exceptionโ€ dialog box in VS with a stack trace from external to internal:

[External code]

PreviewKeyUp event text box

[External code]

Set property of class ClassA

ClassA internal path update function called

Calling the INotifyPropertyChanged Event

[External code]

Getter call for list of class children

Calling ClassB Internal Directory List Function

. App.xaml.cs :

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        Application.Current.Dispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);
    }

. VS, , - . , Application_Startup . "" , ?

, / , .

[]

, WPF. DirectoryInfo ( , ), , - WPF . , - - , , , , , , .

+3
1

DispatcherUnhandledException.

private void Application_Startup(object sender, StartupEventArgs e)
{
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    Application.Current.Dispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);
    this.DispatcherUnhandledException += ...
}
-1

Source: https://habr.com/ru/post/1744453/


All Articles