static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { string To = "*****@*****.**"; string From = To; string Body = "管理员:<br> hello!<br>系统捕获异常:<br>" + e.Exception.StackTrace; string Title = "Error"; string Password = "******"; DialogResult result = DevComponents.DotNetBar.MessageBoxEx.Show("是否将错误信息发送到管理员邮箱?\n[Yes]发送并重启软件 [No]不发送并重启软件 [Cancel]关闭\n异常信息: " + e.ToString(), "[异常]", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); switch (result) { case DialogResult.Yes: { try { using (SendMail sm = new SendMail(To, From, Body, Title, Password)) { sm.Send(); sm.Dispose(); System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); System.Environment.Exit(0); } } catch (Exception ex) { MessageBox.Show("系统出现如下异常:" + ex.ToString()); } break; } case DialogResult.No: { System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); System.Environment.Exit(0); break; } case DialogResult.Cancel: { System.Environment.Exit(0); break; } } }