Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out if a Timer is running?

Tags:

.net

timer

If I have an instance of a System.Timers.Timer that has a long interval - say 1 minute, how can I find out if it is started without waiting for the Tick?

like image 477
George Mauer Avatar asked Sep 29 '08 20:09

George Mauer


People also ask

What is timer enabled in c#?

If Enabled is set to true and AutoReset is set to false , the Timer raises the Elapsed event only once, the first time the interval elapses. If the interval is set after the Timer has started, the count is reset.

How does system timer work?

Remarks. The Timer component is a server-based timer that raises an Elapsed event in your application after the number of milliseconds in the Interval property has elapsed. You can configure the Timer object to raise the event just once or repeatedly using the AutoReset property.

Does timer run on main thread?

If a timer is fired on the main thread's run loop, you will probably have a problem with either the timer function or UI operation. For example, suppose you have triggered a timer. There is also a tableView in your app that shows a list to the user and the user is scrolling the table.

Does system timers timer run in a separate thread?

Yes, they run in a different thread.


2 Answers

System.Timer.Timer.Enabled should work, when you call "Start" it sets Enabled to TRUE, "Stop" sets it to FALSE.

like image 93
Ron Savage Avatar answered Nov 10 '22 01:11

Ron Savage


if (timer1.Enabled) {    // Do Something } 
like image 28
Inisheer Avatar answered Nov 10 '22 03:11

Inisheer