c# - How to block a timer while processing the elapsed event? -
I have a timer that does not process the event handler with its timeframe at the same time. But processing an expired event Maybe can interfere with others I have applied the solution below, but something seems wrong; It seems that I am either using a timer in a different way or using any other object within the threading space. The timer seemed to be the best because I need to check a situation from time to time, but sometimes checking will take longer than my interval Is this the best way to approach?
// Member Variables Private static readonly object timer lock = new object (); Private baul got = wrong; // Somewhere Timer.Internval = Timespace.formsconds (5). Total emiilsecond; Timer.Elapsed = timer_onplay; Timer.start (); Public Zero timer_onepled (object sender, ElapsedEventArgs e) {lock (timer lock) {if (! Found) {found = LookForItWhichMightTakeALongTime (); }}
You can set the auto reset to false, then explicitly You can reset the timer to handle it. Of course, how you handle it depends on how the timer works. Doing this in such a way will prevent your timer from the actual specified interval (such as pausing and restarting). Your system will set fire to each and every interval of fire, but its consequences can be a backlog of unrestricted events which are now handled, where the timer is close to the end where the handler is applied.
timer. Interval = timespan Foamsecond (5). Total EmilisCand; Timer.Elapsed + = Timer_OnElapsed; Timer.AutoReset = false; Timer.start (); Public Zero timer_onepled (object sender, ElapsedEventArgs e) {if (! Found) {found = LookForItWhichMightTakeALongTime (); } Timer.start (); }
Comments
Post a Comment