环境: Windows Server 2003, .NET Framework 2.0程序中已经使用了 Application.ThreadException 和 AppDomain.CurrentDomain.UnhandledException 来处理未捕获的异常, 但异常得到处理之后(比如给出友好提示), 主程序照旧不声不响地退出, 应该怎么办才能使程序继续 ?// Main 函数的源代码mainForm = new PilotageForm();
Application.ThreadException += delegate(object sender, ThreadExceptionEventArgs args) {
  HandleException(args.Exception);
};AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs args) {
  Exception ex = args.ExceptionObject as Exception;
  if (ex == null) { return; }
  if (mainForm.InvokeRequired) {
    mainForm.Invoke(new ExceptionDelegate(HandleException), new object[] { ex });
  } else {
    HandleException(ex);
  }
};Application.Run(mainForm);

解决方案 »

  1.   

    the mechanism is changed in .NET 2.0, an unhandled exception on any thread shuts down the whole application, seehttp://blogs.msdn.com/psfd/archive/2005/08/17/452702.aspxUnhandled Exceptions and Tracing in the .NET Framework 2.0
    http://msdn.microsoft.com/msdnmag/issues/05/07/Bugslayer/default.aspx
      

  2.   

    Application.ThreadException 和 AppDomain.CurrentDomain.UnhandledException 就是相当与主线程的catch段,当然是要退出的了,
    你可以用goto来重新启动程序,但不建议如此,现场已经破坏