In C#, when using the System.Timers.Timer, can the ElapsedEvent run if the previous one has not finished?
Imagine I have an event that takes longer to complete than I anticipated, and the timer’s interval is up, before execution has finished. What happens then?
From what I could read on MSDN, System.Timers run on the threadpool, where as Windows Timers run single threaded.
I am concerned that I will accidently run two (or more!) events at the same time.
Yes, the Elapsed event will be fired again.
Reading carefully the MSDN Documentation that says:
If the SynchronizingObject property is Nothing, the Elapsed event is raised on a ThreadPool thread. If the processing of the Elapsed event lasts longer than Interval, the event might be raised again on another ThreadPool thread. In this situation, the event handler should be reentrant.Also using the Stop method doesn’t ensure the end of Elapsed event because the Stop event could be queued in an different Thread respect the Interval event.
Again reading the MSDN clarifies how to handle this situation