using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Collections; using System.Windows.Forms; using System.Threading; namespace HXX.Scanner.Common { public class CustomExceptionHandlerForClient { public CustomExceptionHandlerForClient() { //处理未捕获的异常 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += new ThreadExceptionEventHandler(this.OnThreadExceptionUI); //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.OnThreadExceptionUnhandled); } private void OnThreadExceptionUI(object sender, ThreadExceptionEventArgs args) { try { LogManager.WriteLog(args.Exception); //MsgManager.Error(args.Exception.Message); } catch (Exception ee) { LogManager.WriteLog(ee); //MsgManager.Error(ee.Message); } } private void OnThreadExceptionUnhandled(object sender, UnhandledExceptionEventArgs args) { try { Exception ee = args.ExceptionObject as Exception; LogManager.WriteLog(ee); //MsgManager.Error(ee.Message); } catch (Exception eee) { LogManager.WriteLog(eee); //MsgManager.Error(eee.Message); } } } public class CustomExceptionHandlerForServer { public CustomExceptionHandlerForServer() { Application.ThreadException += new ThreadExceptionEventHandler(this.OnThreadException); } private void OnThreadException(object sender, ThreadExceptionEventArgs args) { try { LogManager.WriteLog(args.Exception.Message); } catch (Exception ee) { LogManager.WriteLog(ee); LogManager.WriteLog(ee.Message); } } } }