Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do C# Timers elapse on a separate thread?

Does a System.Timers.Timer elapse on a separate thread than the thread that created it?

Lets say I have a class with a timer that fires every 5 seconds. When the timer fires, in the elapsed method, some object is modified. Lets say it takes a long time to modify this object, like 10 seconds. Is it possible that I will run into thread collisions in this scenario?

like image 680
user113164 Avatar asked Sep 16 '09 22:09

user113164


People also ask

Apa saja deret nada pada nada do C?

C = Do adalah C - D - E - F - G - A - B - C dengan interval 1 – 1 – 1 – 1/2 – 1 – 1 – 1/2.

Apa arti C DO dalam partitur lagu berjudul Aku Cinta Lingkungan?

Do = C artinya nada do pada tangga nada tersebut tinggi/rendahnya adalah setinggi nada C.

Apa artinya dari Do C?

Apabila nada dasarnya – C mayor, maka nada C inilah yang menjadi nada do (C=do / C=1; atau do=C / 1=C).

Apa arti tanda DO C dalam sebuah lagu brainly?

Lagu daerah ciptaan R.C Hardjosubroto ini dinyanyikan dengan nada dasar Do=C. Artinya nada do pada tangga nada, tinggi atau rendahnya setinggi nada C. Tentu teman-teman masih mengingat pelajaran nada tangga mayor, bukan?


1 Answers

It depends. The System.Timers.Timer has two modes of operation.

If SynchronizingObject is set to an ISynchronizeInvoke instance then the Elapsed event will execute on the thread hosting the synchronizing object. Usually these ISynchronizeInvoke instances are none other than plain old Control and Form instances that we are all familiar with. So in that case the Elapsed event is invoked on the UI thread and it behaves similar to the System.Windows.Forms.Timer. Otherwise, it really depends on the specific ISynchronizeInvoke instance that was used.

If SynchronizingObject is null then the Elapsed event is invoked on a ThreadPool thread and it behaves similar to the System.Threading.Timer. In fact, it actually uses a System.Threading.Timer behind the scenes and does the marshaling operation after it receives the timer callback if needed.

like image 154
Brian Gideon Avatar answered Sep 23 '22 03:09

Brian Gideon