You need to handle the System.Windows.Forms.Application.ThreadException event for Windows Forms. This article really helped me: http://bytes.com/forum/thread236199.html.

Application.ThreadException += new ThreadExceptionEventHandler(MyCommonExceptionHandlingMethod)

private static void MyCommonExceptionHandlingMethod(object sender, ThreadExceptionEventArgs t)
{
//Exception handling...
}
AppDomain.UnhandledException and Application.ThreadException.

http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

using System;
using System.Security.Permissions; public class Example
{
[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
public static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); try {
throw new Exception("");
} catch (Exception e) {
Console.WriteLine("Catch clause caught : {0} \n", e.Message);
} throw new Exception("");
} static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
}
}

Catch Application Exceptions in a Windows Forms Application的更多相关文章

  1. create Context Menu in Windows Forms application using C# z

    In this article let us see how to create Context Menu in Windows Forms application using C# Introduc ...

  2. 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别

    原文:[C#遗补]获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPa ...

  3. Windows Forms Application Creation and Initialization

    Windows Forms Application Creation and Initialization This topic details the steps performed after a ...

  4. System.Windows.Forms.Application.DoEvents();

    关于Application.DoEvents()的小研究 在MSDN中的备注是: 当运行 Windows 窗体时,它将创建新窗体,然后该窗体等待处理事件.该窗体在每次处理事件时,均将处理与该事件关联的 ...

  5. Windows Forms (一)

    导读 1.什么是 Windows Forms 2.需要学Windows Forms 么? 3.如何手写一个简单的Windows Forms 程序 4.对上面程序的说明 5.Form 类与Control ...

  6. 如何为Windows Forms应用程序添加启动参数(Start-Up Parameters)

    很多场合下,我们需要通过命令行或者快捷方式在Windows Forms程序启动时向其传递参数. 这些参数可能是用来加载某一个文档,或者是应用程序的初始化配置文件. 特别是对那些需要高度自定义配置的大程 ...

  7. Delphi10.2 VCL Forms Application 的构成

    Delphi10.2 项目的构成(File Extensions of Files Generated by RAD Studio) Step1.打开 Delphi10.2,选择[File | New ...

  8. 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Application Data 中的媒体

    [源码下载] 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Ap ...

  9. Unity 读取、写入自定义路径文件,调用System.Windows.Forms

    调用System.Windows.Forms DLL 首先在Unity新建Plugins文件夹添加System.Windows.Forms.dll 然后代码中添加引用 using System; us ...

随机推荐

  1. TCP/IP协议原理与应用笔记03:IP地址分类

    1. 事实上,每个IP地址都包含两部分,即网络号和主机号. 例如:202.112.81.34指的 就是202.112.81这个网络的第34号机. 网络号:用于识别主机所在的网络: 主机号:用于识别该网 ...

  2. ios通知-kvo

    // KVC: Key Value Coding, 常见作用:给模型属性赋值    // KVO: Key Value Observing, 常用作用:监听模型属性值的改变 // // ViewCon ...

  3. Listview实现分页下载

    分析: * 1.初始控件,展示第一页数据 * 2.设置触发条件 * 1.设置滚动监听 * 2.判断是否在底部 * 3.判断是否停止滚动 * 4.更改网络请求参数为下一页 * 5.异步网络请求 * 6. ...

  4. C语言---注释

    1.单行注释 //注释内容 2.多行注释 /*注释内容*/ 3.#if 0 注释内容 #endif 说明: 1.单行注释//不通用,有些编译器不支持 2.多行注释不能嵌套 3.#if 0 #endif ...

  5. 关于Eclipse中的一些基本知识

    Eclipse中寻找JRE的顺序是:vm参数指定的JRE--->elipse目录下的JRE--->操作系统中默认的JRE,利用这个特性也可以用vm参数来解决当本机安装有多个JRE的情况. ...

  6. jQuery图片无缝滚动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. CentOS 7 安装virtualBox

    sudo rpm -ivh rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm sudo yum install VirtualBox-5.0

  8. 安装Numpy和matplotlib

    (1)测试程序     这是我从网上(http://www.open-open.com/lib/view/open1393488232380.html)找到的一个使用Numpy和matplotlib的 ...

  9. Acitivity间数据的传递

    使用startActivityForResult方法进行数据传递.    MainActivity.java: public class MainActivity extends Activity { ...

  10. Ubuntu Update-rc.d命令详细介绍

    http://www.jb51.net/os/Ubuntu/182768.html Ubuntu或者Debian系统中update-rc.d命令,是用来更新系统启动项的脚本.这些脚本的链接位于/etc ...