日期:2014-05-20  浏览次数:20813 次

.net 程序无报错自动关闭。
我用winForm写了一个程序,
程序里开了近10几个线程 一直在跑while true ... end while,或者定时器。
持续跑了很多天。
各个地方都写了try catch. 却偶尔出现过几次程序无报错就自动自动关闭.
1. 确定是程序自己关闭,不是电脑重启的原因.
2. 所有的try catch都记了日志,却没有任何自动关闭的相关错误信息。
3. 状态日志每两分钟记录了程序在电脑上运行的性能状态,内存和句柄数都在正常范围。
4. 在Main_FormClosed写了‘系统关闭’的日志,但程序自动关闭时也没有跑这个事件。



请问,1.多线程程序出现这种问题,有可能是什么原因导致。
2.如何监测try catch以外的错误,是不是这个类型的错误,导致的程序自动关闭。

------解决方案--------------------
public static void Main(string[] args)
{
   // Add the event handler for handling UI thread exceptions to the event.
    Application.ThreadException += new     
  ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);

  // Set the unhandled exception mode to force all Windows Forms errors
  // to go through our handler.
  Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

  // Add the event handler for handling non-UI thread exceptions to the event. 
  AppDomain.CurrentDomain.UnhandledException += new       
  UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
  
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/