在C# Winform桌面应用程序中,我正在尝试捕获所有可能出现的异常,我尝试过的方法是:
using System;
using System.Threading;
using System.Windows.Forms;
namespace Controller
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.Run(new Form1());
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message, "Unhandled Thread Exception");
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show((e.ExceptionObject as Exception).Message, "Unhandled UI Exception");
}
}
}
我在关闭表单事件时附加“COM6”进行测试,但在设备管理器中未找到串口,只看到Visual Studio An exception of type 'System.InvalidOperationException' occurred in System.dll but was not handled in user code
报告。
如何收集WinForm应用程序的错误数据?