Catch Application Exceptions in a Windows Forms Application
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的更多相关文章
- 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 ...
- 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别
原文:[C#遗补]获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPa ...
- Windows Forms Application Creation and Initialization
Windows Forms Application Creation and Initialization This topic details the steps performed after a ...
- System.Windows.Forms.Application.DoEvents();
关于Application.DoEvents()的小研究 在MSDN中的备注是: 当运行 Windows 窗体时,它将创建新窗体,然后该窗体等待处理事件.该窗体在每次处理事件时,均将处理与该事件关联的 ...
- Windows Forms (一)
导读 1.什么是 Windows Forms 2.需要学Windows Forms 么? 3.如何手写一个简单的Windows Forms 程序 4.对上面程序的说明 5.Form 类与Control ...
- 如何为Windows Forms应用程序添加启动参数(Start-Up Parameters)
很多场合下,我们需要通过命令行或者快捷方式在Windows Forms程序启动时向其传递参数. 这些参数可能是用来加载某一个文档,或者是应用程序的初始化配置文件. 特别是对那些需要高度自定义配置的大程 ...
- Delphi10.2 VCL Forms Application 的构成
Delphi10.2 项目的构成(File Extensions of Files Generated by RAD Studio) Step1.打开 Delphi10.2,选择[File | New ...
- 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Application Data 中的媒体
[源码下载] 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Ap ...
- Unity 读取、写入自定义路径文件,调用System.Windows.Forms
调用System.Windows.Forms DLL 首先在Unity新建Plugins文件夹添加System.Windows.Forms.dll 然后代码中添加引用 using System; us ...
随机推荐
- Asp.Net 之 获取GridView行的DataKeys
1.后台任意一个位置获取GridView行的主键值 foreach (GridViewRow row in GridView1.Rows) { string order_Id=this.GridVie ...
- android开发之路02(浅谈BroadcastReceiver)
一.BroadcastReceiver (广播接收者)的作用是用来接收来自系统和应用中的广播.应用如下: 1.开机完成后系统会产生一条广播----->接收到这条广播就能实现开机启动服务的功能: ...
- 使用SDWebImage 怎么获取指定请求对应的缓存图片呢?
SDWebImage会对我们加载的网络数据进行缓存,但有时候我们想要拿到缓存数据中的图片,可以通过下个方法实现: UIImage *thumbnailImage = [[SDImageCache sh ...
- 配置Linux数据转发(给其他接口转发一个接口的internet网络)
配置Linux数据转发 [主机]第一步开启转发net.ipv4.ip_forward = 1echo "1" > /proc/sys/net/ipv4/ip_forward第 ...
- ttt
<style> .head1{ background:rgb(51,51,51); height:49px; min-width:1241px; width:100%; z-index:1 ...
- MyEclipse build path修改问题
- Spring切面处理
切面类DictionaryAOP 里面有一个全局变量systemTestDomain <bean id="dictionaryAOP" class="test.Di ...
- 批处理 Mysql Findstr
@set Dump_IP=localhost @set User_Name=root @set Password=1234 @set curPath=%~dp0 mysql -h %Dump_IP% ...
- Ubuntu将程序图标加到启动器
问题: Ubuntu中安装一些程序的时候图标可能没有放到启动器中,不方便使用. 解决问题: 因为FileZilla这个程序是直接解压缩之后便可以使用的,每次都需要到文件所在目录Filezilla/bi ...
- 第九篇、UITabbar增加类别用来标红点
1.系统中只有设置bage的方式,设置为nil也是为一个红点,但是很大,并不是我们需要的 2.扩充标红点的方法 (常用于有新的动态提示标志) #import <UIKit/UIKit.h> ...