Questions tagged [timer]

Timer is a component that has the functionality to trigger a user defined action at regular intervals as configured by the user.

Timer is a component that has the functionality to trigger a user defined action at regular intervals as configured by the user.

Some timers (such as Java Swing timer, WPF DispatcherTimer, WinForms Timer) are also capable of firing they events in GUI thread so there is no need to switch into this thread in order to update the components. Other timers do not have this capability and are more optimized to handle big number of scheduled events.

Depending on how does the scheduler behaves if the new even should be fired when the current event has not yet been fully processed, the timer may be coalescing or non coalescing. A coalescing timer reduces multiple pending events to a single event, reducing the number of events to handle. A non-coalescing timer fires pending overtime events in rapid succession with no delay between them, in order to catch up.

19566 questions
190
votes
4 answers

Where is the WPF Timer control?

Where can I find a control which is like the C# Timer Control in WPF?
cetin
  • 2,025
  • 4
  • 17
  • 9
172
votes
5 answers

How to set a Timer in Java?

How to set a Timer, say for 2 minutes, to try to connect to a Database then throw exception if there is any issue in connection?
Ankita
  • 1,813
  • 2
  • 17
  • 16
168
votes
9 answers

Executing periodic actions

I am working on Windows. I want to execute a function foo() every 10 seconds. How do I do this?
Bruce
  • 33,927
  • 76
  • 174
  • 262
162
votes
9 answers

How to run a method every X seconds

I'm developing an Android 2.3.3 application and I need to run a method every X seconds. In iOS, I have NSTimer, but in Android I don't know what to use. Someone have recommend me Handler; another recommend me AlarmManager but I don't know which…
VansFannel
  • 45,055
  • 107
  • 359
  • 626
154
votes
12 answers

How do you add a timer to a C# console application

Just this - How do you add a timer to a C# console application? It would be great if you could supply some example coding.
Johan Bresler
  • 6,450
  • 11
  • 56
  • 77
153
votes
13 answers

Code for a simple JavaScript countdown timer?

I want to use a simple countdown timer starting at 30 seconds from when the function is run and ending at 0. No milliseconds. How can it be coded?
Michael Swarts
  • 3,813
  • 8
  • 31
  • 41
151
votes
14 answers

Print "hello world" every X seconds

Lately I've been using loops with large numbers to print out Hello World: int counter = 0; while(true) { //loop for ~5 seconds for(int i = 0; i < 2147483647 ; i++) { //another loop because it's 2012 and PCs have gotten considerably…
meiryo
  • 11,157
  • 14
  • 47
  • 52
143
votes
11 answers

Calling a method every x minutes

I want to call some method on every 5 minutes. How can I do this? public class Program { static void Main(string[] args) { Console.WriteLine("*** calling MyMethod *** "); Console.ReadLine(); } private MyMethod() …
user1765862
  • 13,635
  • 28
  • 115
  • 220
134
votes
11 answers

How to reset a timer in C#?

There are three Timer classes that I am aware of, System.Threading.Timer, System.Timers.Timer, and System.Windows.Forms.Timer, but none of these have a .Reset() function which would reset the current elapsed time to 0. Is there a BCL class that has…
Matthew Scharley
  • 127,823
  • 52
  • 194
  • 222
132
votes
8 answers

setTimeout / clearTimeout problems

I try to make a page to go to the startpage after eg. 10sec of inactivity (user not clicking anywhere). I use jQuery for the rest but the set/clear in my test function are pure javascript. In my frustation I ended up with something like this…
Tillebeck
  • 3,493
  • 7
  • 42
  • 63
131
votes
14 answers

Flutter Countdown Timer

How can I do to put the value passed in the construction, to make a timer that rounds to the first decimal and shows at the child text of my RaisedButton? I've tried but without luck. I manage to make work the callback function with a simple Timer…
Floris Marpepa
  • 1,891
  • 4
  • 12
  • 22
124
votes
5 answers

How to get duration, as int milli's and float seconds from ?

I'm trying to use chrono library for timers and durations. I want to be able to have a Duration frameStart; ( from app start ) and a Duration frameDelta; ( time between frames ) I need to be able to get the frameDelta duration as milliseconds and…
EddieV223
  • 5,085
  • 11
  • 36
  • 38
124
votes
16 answers

threading.Timer - repeat function every 'n' seconds

I want to fire off a function every 0.5 seconds and be able to start and stop and reset the timer. I'm not too knowledgeable of how Python threads work and am having difficulties with the python timer. However, I keep getting RuntimeError: threads…
user1431282
  • 6,535
  • 13
  • 51
  • 68
116
votes
9 answers

What is the simplest way to run a timer-triggered Azure Function locally once?

I have a few C# Azure Functions that run on a schedule using timer triggers. I've set them up like so, where %TimerSchedule% refers to a cron expression in the app settings: public static void Run([TimerTrigger("%TimerSchedule%")]TimerInfo myTimer,…
Reilly Wood
  • 1,753
  • 2
  • 12
  • 17
115
votes
5 answers

System.Threading.Timer in C# it seems to be not working. It runs very fast every 3 second

I've a timer object. I want it to be run every minute. Specifically, it should run a OnCallBack method and gets inactive while a OnCallBack method is running. Once a OnCallBack method finishes, it (a OnCallBack) restarts a timer. Here is what I have…
Alan Coromano
  • 24,958
  • 53
  • 135
  • 205