我在一个应用程序中,开启了多个线程,然后执行不同的任务,在这些线程中,可能会再开启子线程。现在出现一个问题,程序有时候会异常退出,整个应用程序崩溃,我已在各个环节加上了trycatch,但依然会导致程序退出,从系统事件中看到一个错误:.NET Runtime version 2.0.50727.3625 - 执行引擎错误(7A0BC59E) (80131506)该怎么办,怎样可以隔离开每个线程,用Appdomain可以吗?也就是如果某一个线程中执行的任务出现错误导致崩溃,不会影响到其它线程。

解决方案 »

  1.   

    在program.cs里加上如下代码,错误日志里会记录出错的行数。
            static Program()
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            }        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
            {
                string strException = string.Format("{0}发生系统异常。\r\n{1}\r\n\r\n\r\n", DateTime.Now, e.ExceptionObject.ToString());
                File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemException.log"), strException);
            }