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
760
votes
6 answers

How do I get my program to sleep for 50 milliseconds?

How do I get my Python program to sleep for 50 milliseconds?
TK.
  • 46,577
  • 46
  • 119
  • 147
692
votes
8 answers

Calculate the execution time of a method

Possible Duplicate: How do I measure how long a function is running? I have an I/O time-taking method which copies data from a location to another. What's the best and most real way of calculating the execution time? Thread? Timer? Stopwatch? Any…
Mahdi Tahsildari
  • 13,065
  • 14
  • 55
  • 94
637
votes
7 answers

What's the easiest way to call a function every 5 seconds in jQuery?

JQuery, how to call a function every 5 seconds. I'm looking for a way to automate the changing of images in a slideshow. I'd rather not install any other 3rd party plugins if possible.
ensnare
  • 40,069
  • 64
  • 158
  • 224
633
votes
9 answers

System.Timers.Timer vs System.Threading.Timer

I have been checking out some of the possible timers lately, and System.Threading.Timer and System.Timers.Timer are the ones that look needful to me (since they support thread pooling). I am making a game, and I plan on using all types of events,…
TheAJ
  • 10,485
  • 11
  • 38
  • 57
494
votes
16 answers

Is DateTime.Now the best way to measure a function's performance?

I need to find a bottleneck and need to accurately as possible measure time. Is the following code snippet the best way to measure the performance? DateTime startTime = DateTime.Now; // Some execution process DateTime endTime =…
David Basarab
  • 72,212
  • 42
  • 129
  • 156
481
votes
22 answers

How to repeatedly execute a function every x seconds?

I want to repeatedly execute a function in Python every 60 seconds forever (just like an NSTimer in Objective C or setTimeout in JS). This code will run as a daemon and is effectively like calling the python script every minute using a cron, but…
davidmytton
  • 38,604
  • 37
  • 87
  • 93
415
votes
10 answers

System.currentTimeMillis vs System.nanoTime

Accuracy Vs. Precision What I would like to know is whether I should use System.currentTimeMillis() or System.nanoTime() when updating my object's positions in my game? Their change in movement is directly proportional to the elapsed time since the…
mmcdole
  • 91,488
  • 60
  • 186
  • 222
376
votes
24 answers

How to set timer in android?

Can someone give a simple example of updating a textfield every second or so? I want to make a flying ball and need to calculate/update the ball coordinates every second, that's why I need some sort of a timer. I don't get anything from here.
SERG
  • 3,907
  • 8
  • 44
  • 89
316
votes
3 answers

How to write a countdown timer in JavaScript?

Just wanted to ask how to create the simplest possible countdown timer. There'll be a sentence on the site saying: "Registration closes in 05:00 minutes!" So, what I want to do is to create a simple js countdown timer that goes from "05:00" to…
Bartek
  • 3,203
  • 3
  • 12
  • 5
304
votes
6 answers

Java Timer vs ExecutorService?

I have code where I schedule a task using java.util.Timer. I was looking around and saw ExecutorService can do the same. So this question here, have you used Timer and ExecutorService to schedule tasks, what is the benefit of one using over…
kal
  • 28,545
  • 49
  • 129
  • 149
304
votes
15 answers

Calling a function every 60 seconds

Using setTimeout() it is possible to launch a function at a specified time: setTimeout(function, 60000); But what if I would like to launch the function multiple times? Every time a time interval passes, I would like to execute the function (every…
Richard Knop
  • 81,041
  • 149
  • 392
  • 552
282
votes
18 answers

How to timeout a thread

I want to run a thread for some fixed amount of time. If it is not completed within that time, I want to either kill it, throw some exception, or handle it in some way. How can it be done? One way of doing it as I figured out from this thread is to…
java_geek
  • 17,585
  • 30
  • 91
  • 113
224
votes
16 answers

How to make a countdown timer in Android?

I have two EditTexts in XML. In one EditText, the user can put a number as minutes and in another EditText, a number as seconds. After clicking the finish button, the seconds EditText should start to countdown and update its text every second.…
Sabbir Ahmed
  • 2,297
  • 2
  • 15
  • 13
196
votes
17 answers

Changing the interval of SetInterval while it's running

I have written a javascript function that uses setInterval to manipulate a string every tenth of a second for a certain number of iterations. function timer() { var section = document.getElementById('txt').value; var len = section.length; …
Joe Di Stefano
  • 2,157
  • 2
  • 13
  • 8
191
votes
12 answers

Run a java function after a specific number of seconds

I have a specific function that I want to be executed after 5 seconds. How can I do that in Java? I found javax.swing.timer, but I can't really understand how to use it. It looks like I'm looking for something way simpler then this class…
ufk
  • 30,912
  • 70
  • 235
  • 386
1
2 3
99 100