110,566
社区成员
发帖
与我相关
我的任务
分享
=====================================
使用全局事件扑捉
=====================================
using System;
using System.Windows.Forms;
//using Microsoft.Win32;
//注册全局的异常处理程序,扑获产生的异常。
namespace Zhengzuo.CSharpCode
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
if ( false == SingleInstance.HandleRunningInstance() )
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
//SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain());
}
}
//static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
//{
// throw new Exception("The method or operation is not implemented.");
//}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
}
}