Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elapsed event v Tick event?

Tags:

c#

timer

Is the Elapsed event of System.Timers.Timer effectively the same as the Tick event of System.Windows.Forms.Timer?

In specific circumstances are there advantages of using one rather than the other?

like image 710
whytheq Avatar asked Apr 13 '12 07:04

whytheq


2 Answers

The other answers provide a lot of detail, but the overriding difference between the two timers you mentioned is that the System.Windows.Forms.Timer will invoke the callback on the UI thread, whereas the System.Timers.Timer will use one of the threads from the core thread pool.

like image 129
SimonC Avatar answered Sep 19 '22 14:09

SimonC


Check these links here and here for complete understanding of timers in .Net framework.

There are three types of timers.

  • System.Windows.Forms.Timer
  • System.Timers.Timer
  • System.Threading.Timer

I personally prefers System.Timers.Timer as it's thread-safe.

like image 20
ABH Avatar answered Sep 21 '22 14:09

ABH