首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-05-12 
winform中是否存在类似全局处理异常的设施?我们知道asp.net有个Global.asax,其中Appliction_Error事件方法

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楼正解。

热点排行