Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows.Forms.Timer OR System.Threading.Timer

Tags:

c#

.net

timer

I have an application that runs many threads. Each thread should have a timer that checks for something in that thread's scope. My question is: Which timer I should use and what is the difference between them?

like image 526
deadlock Avatar asked Dec 26 '10 05:12

deadlock


People also ask

What is System threading timer?

System. Threading. Timer, which executes a single callback method on a thread pool thread at regular intervals. The callback method is defined when the timer is instantiated and cannot be changed.

Does System timers timer run in a separate thread?

Yes, they run in a different thread.

Is System threading timer thread safe?

Timer is not thread-safe.


1 Answers

This article provides an excellent comparison and should contain the information you need: Comparing the Timer Classes in the .NET Framework Class Library:

                                    Windows.Forms  System.Timers         System.Threading  Timer event runs on what thread?    UI thread      UI or worker thread   Worker thread  Instances are thread safe?          No             Yes                   No  Familiar/intuitive object model?    Yes            Yes                   No  Requires Windows Forms?             Yes            No                    No  Metronome-quality beat?             No             Yes*                  Yes*  Timer event supports state object?  No             No                    Yes  Initial timer event schedulable?    No             No                    Yes  Class supports inheritance?         Yes            Yes                   No  

* Depending on the availability of system resources (for example, worker threads)
like image 97
Mitch Wheat Avatar answered Sep 16 '22 21:09

Mitch Wheat