Admiral Land
Admiral Land

Reputation: 2492

Can System.Timers.Timer elapsed event if previous event still working?

Can System.Timers.Timer elapsed event if previous event still working?

For example, i set Interval 100 ms, but code in handler works 200 ms.

 _taskTimer = new System.Timers.Timer();
 _taskTimer.Interval = 100;
 _taskTimer.Elapsed += _taskTimer_Elapsed;

void _taskTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
        Work(); // works 200 ms.
}

Is timer "wait" while Work() method ends? Or execute a new one? Thank you!

Upvotes: 1

Views: 1989

Answers (3)

StartCoding
StartCoding

Reputation: 393

Internally system.timers.timer also uses system.threading.timers, so the execution process continues even after elapsed fires new execution.

Have a look at the source code of System.Timers.Timer: Timers.Cs

Upvotes: 2

Pranay Rana
Pranay Rana

Reputation: 176956

System.Timers.Timer(Multi Threaded Timer) is multithreaded timer. that means it executes it elapse event on multiple thread and that means it don't wait for previous elapse event.

if you want to wait for previous elapse event to complete that you can use System.Windows.Timer (Single Threaded Timer) - this is single threaded timer will execute event on single thread only(UI thread) which created timer.

You can read more about this here : Timers written by Joe Albahari

Upvotes: 4

Anup Sharma
Anup Sharma

Reputation: 2083

It will Continue Executing on different thread

For reference you can visit this page

Upvotes: 1

Related Questions