문제

I am registering to un-handled exception of my WPF Application.

After UnhandledExceptionHandler invokes, the application will close automatically ? Or do I need to call ShutdownProcess();

Is this enough ?

    static void Main(string[] args)
    {
        //Register to unhandled exception for this application
        AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;


    static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
    {
        try
        {
            Exception ex = (Exception)args.ExceptionObject;
            _logger.ErrorFormat("Process caught unhandled exception, Exception = {0}", ex);
            ShutdownProcess();
        }
        catch
        {
            // swallow silently... nothing we can do.
        }
    }
도움이 되었습니까?

해결책

From MSDN:

"This event provides notification of uncaught exceptions. It allows the application to log information about the exception before the system default handler reports the exception to the user and terminates the application."

So the ugly Popup will be displayed regardless what you are doing in your Handler and the application will be terminated after that. If you don't want the default error popup to be displayed you should add a handler to Application.Current.DispatcherUnhandledException log your errors and call Application.Current.Shutdown() yourself.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top