Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Winforms Application UnhandledExceptionEventHandler SetUnhandledExceptionMode #50

Open
viebrix opened this issue Aug 4, 2023 · 0 comments

Comments

@viebrix
Copy link

viebrix commented Aug 4, 2023

Firstly thanks for this great project. It's exactly what I have searched and needed.
My issue is more a question.
I'm starting to use Dapplo with Winforms for DI, to have the possibility to use same code for a web api.

Until now, in my Winforms (GUI) programs I used - additional to Exception handling - following code in program.cs:

 System.Windows.Forms.Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException,false);
 public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            log.Error(e);
            MessageBox.Show((e.ExceptionObject as Exception).Message, "Unhandled UI Exception");
            // here you can handle the exception ...
        }
        public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            log.Error(e);
            MessageBox.Show(e.Exception.Message, "Unhandled Thread Exception");
            // here you can handle the exception ...
        }

I have read that those events only work if Application.Run was started. Therefore I have the suspicion that those won't work with using: .UseWinFormsLifetime()
Is this correct? Are there any possibilities to include such central exception handling without losing user data in the form?
Thanks a lot for your great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant