Timers in .NET

  • Thread starter Thread starter Ashish Sheth
  • Start date Start date
A

Ashish Sheth

Hi Gurus,
There are three(as far as I know) Timer classes available in .NET, one is in
System.Threading namespace, second is in System.Timers namespace and another
one is System.Windows.Forms namespace. Why? what are the differences between
all these Timer classes? When I should use which class?

Basically I am calling one method in my class asynchronously(using
delegates). After some time I need to call that method again asynchronously.
At this time the first asynchronous call to the method should be completed.
If it is not completed then I should wait for the first call to be
completed. How can I achieve this thing?

thanks and regards,
Ashish Sheth
 
Ashish Sheth said:
There are three(as far as I know) Timer classes available in .NET, one is in
System.Threading namespace, second is in System.Timers namespace and another
one is System.Windows.Forms namespace. Why? what are the differences between
all these Timer classes? When I should use which class?

Basically I am calling one method in my class asynchronously(using
delegates). After some time I need to call that method again asynchronously.
At this time the first asynchronous call to the method should be completed.
If it is not completed then I should wait for the first call to be
completed. How can I achieve this thing?

See http://www.pobox.com/~skeet/csharp/threads/timers.shtml
 
While the System.Windows.Forms.Timer runs on the same thread the UI is
running, the other two run on a seperate thread. This means that if the
process for which you are using the timer takes more time than the interval
of the timer, you're going to miss the intervals in case of the
System.Windows.Forms.Timer since its running on the same thread.
Here's what the MSDN documentation says about the Forms Timer:
http://msdn.microsoft.com/library/d...ml/frlrfSystemWindowsFormsTimerClassTopic.asp

I haven't used System.Timers.Timer but have used the System.Threading.Timer
and it works pretty well. I don't there's a whole lot of difference between
the two as far as functionality is concerned.

hope this helps.
Imran.
 
Back
Top