日期:2014-05-16  浏览次数:20783 次

如何捕获定时器中的异常?
本帖最后由 athwind 于 2014-03-21 03:28:38 编辑

            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
......

这种方法能捕获主线程和普通线程(new Thread())中的异常,好像不能捕获定时器触发方法体timer_Elapsed中的异常,我用的是 System.Timers.Timer。
------解决方案--------------------
请在timer_Elapsed中捕获异常
------解决方案--------------------
http://bbs.csdn.net/topics/360094034
只能在timer_Elapsed中捕获异常。