读书人

winform中是否存在类似全局处理错误的

发布时间: 2012-05-12 15:39:31 作者: rapoo

winform中是否存在类似全局处理异常的设施?
我们知道asp.net有个Global.asax,其中Appliction_Error事件方法,可以对应用程序级的异常进行处理。不知道winform中有吗?在哪里?谢谢~

[解决办法]
// Add the event handler for handling UI thread exceptions to the event.
Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);

// Set the unhandled exception mode to force all Windows Forms errors to go through
// our handler.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
[解决办法]
项目右击属性,点击【查看应用程序时间】按钮,找到MyApplication的UnhandledException事件就是你要的了。
[解决办法]

C# code
 Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);
[解决办法]
楼主看2楼
[解决办法]
2楼正解。

读书人网 >C#

热点推荐