c# - Having two System.Timer.Timer objects in your class and catching exceptions -


i have class 2 system.timers.timer objects. see now, exception thrown in one, caught other. correct behaviour?

class myclass {     system.timers.timer tone;     system.timers.timer ttwo;      tone.elapsed += new system.timers.elapsedeventhandler(one);     ttwo.elapsed += new system.timers.elapsedeventhandler(two);      void one(object sender, system.timers.elapsedeventargs e) {         try {              .. code throws ...         } catch (exception) {                // not caught here         }     }      void two(object sender, system.timers.elapsedeventargs e) {         try {         } catch (exception) {                // caught here         }     } } 

different timers, exception caught first timer ticks after exception thrown. problem because use single thread.

system.timers.timer silently swallow exceptions , continue timer (although subject change in future versions of framework); system.threading.timer terminate program.


Comments