Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > C#.NET > Catch UnHanle Exception in WinForm
【标  题】:Catch UnHanle Exception in WinForm
【关键字】:Catch,UnHanle,Exception,in,WinForm
【来  源】:http://jigee.cnblogs.com/archive/2006/05/08/393853.html

Catch UnHanle Exception in WinForm

Your Ad Here as we know, we can catch unhanle exception like this:
AppDomain.CurrentDomain.UnhandledException+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    Application.ThreadException
+=new ThreadExceptionEventHandler(Application_ThreadException);

but if you call winForm like this, the style above will not affect all time, just occasionlly:

//add handler

AppDomain.CurrentDomain.UnhandledException
+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    Application.ThreadException
+=new ThreadExceptionEventHandler(Application_ThreadException);

//initial system

Application.Run(
new Form1());

//main form

Application.Run(
new Form2());

 since when Application.Run, it begins one Message Loop in current main thread, and the thread exception's hook work.

but when Form1 close, the thread hook release, but then we begin the other message loop, the exception's hook release,

so if we hook it twice, what happen?

//add handler

AppDomain.CurrentDomain.UnhandledException
+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    Application.ThreadException
+=new ThreadExceptionEventHandler(Application_ThreadException);

//initial system

Application.Run(
new Form1());

//main form
ThreadExceptionEventHandler(Application_ThreadException);
Application.Run(
new Form2());

 

要得都给你:【上一篇】
"Atlas" Control Toolkit更新发布(Version 1.0.60504.0):【下一篇】
【相关文章】
  • Windows Workflow Foundation (wwf) 学习笔记(二)
  • Atlas Control Toolkit Demo:从数据库中取得数据并填充CascadingDropDown控件
  • php.ini 中文版
  • Linux内核中的一些基本操作
  • 转载——关于fflush(stdin)的误区
  • 深入浅出Win32多线程程序设计 ---- 线程控制
  • windows2000/xp无法获取ip地址现象
  • Linux下NAT功能的实现
  • 关于asp中的.inc
  • 多系统安装实践(Window 2000、FreeBSD、Linux)
  • 【随机文章】
  • RealPlayer/One中切换左右声道
  • 函数名称 StrIComp
  • Matlab Add-in 与VC++ 的混合编程技术
  • solaris 系统截图
  • 送给新手朋友们的见面礼,以前做的教学视频提供下载
  • 如何用DOM4J编程使用xml schema
  • 脱胎换骨,如释重负。。。
  • JBoss Portal 2.6 DR1 发布
  • 8月学习记录
  • C++Builder的多线程编程中一些体会
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.