当自己定义的线程出现异常,怎样通知给主线程,static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{ MessageBox.Show(DateTime.Now.ToString());
}
进入到这个方法进行统一的处理啊???????????????????
{ MessageBox.Show(DateTime.Now.ToString());
}
进入到这个方法进行统一的处理啊???????????????????
Application.ThreadException
AppDomain.CurrentDomain.UnhandledException
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
{
//throw new Exception();
LoadForm();
#if DEBUG
// MessageBox.Show(DateTime.Now.Minute.ToString());
#endif
}
private void LoadForm()
{
//try
//{
// int i = Convert.ToInt32("asd");
//}
//catch (Exception e)
//{ // throw new Exception(e.Message);
//}
Thread td = new Thread(new ThreadStart(start));
td.Start();
} private void start()
{
throw new Exception();
}static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{ MessageBox.Show(DateTime.Now.ToString());
}
不知道怎么进不来啊????????
{
//throw new Exception();
LoadForm();
#if DEBUG
// MessageBox.Show(DateTime.Now.Minute.ToString());
#endif
}
private void LoadForm()
{
//try
//{
// int i = Convert.ToInt32("asd");
//}
//catch (Exception e)
//{ // throw new Exception(e.Message);
//}
Thread td = new Thread(new ThreadStart(start));
td.Start();
} private void start()
{
throw new Exception();
}static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{ MessageBox.Show(DateTime.Now.ToString());
}
不知道怎么进不来啊????????
#if !DEBUG
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
#endif同时再添加两个方法处理异常信息! static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
} static void UnhandledExceptionFunction(Object sender, UnhandledExceptionEventArgs args)
{
MessageBox.Show(((Exception)args.ExceptionObject).Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}其它主要处理子线程错误的就只有这两行
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionFunction);
以及UnhandledExceptionFunction方法这样就可以捕捉到子线程的异常了