Prevent “Send error report to Microsoft”

后端 未结 6 2203
眼角桃花
眼角桃花 2021-01-04 20:47

I\'m working on a rather large project, and its unlikely will catch everything. I\'ve found the event that notifies me of unhandled exceptions, however I haven\'t found a wa

6条回答
  •  逝去的感伤
    2021-01-04 21:47

    This is what we did.

    static void Main() {
        try
        {
            SubMain();
        }
        catch (Exception e)
        {
            HandleUnhandledException(e);
        }
    }
    
    private static void SubMain()
    {
        // Setup unhandled exception handlers
        AppDomain.CurrentDomain.UnhandledException += // CLR
           new UnhandledExceptionEventHandler(OnUnhandledException);
         Application.ThreadException += // Windows Forms
           new System.Threading.ThreadExceptionEventHandler(
               OnGuiUnhandledException);
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(new frmMain());
    }
    
    // CLR unhandled exception
    private static void OnUnhandledException(Object sender,
       UnhandledExceptionEventArgs e)
    {
        HandleUnhandledException(e.ExceptionObject);
    }
    
    // Windows Forms unhandled exception
    private static void OnGuiUnhandledException(Object sender,
       System.Threading.ThreadExceptionEventArgs e)
    {
        HandleUnhandledException(e.Exception);
    }
    

提交回复
热议问题