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
4
votes
2 answers

C++ Snake clone: timer function ignores given stop time and stops at it's own fixed time

I'm trying to make a Snake clone using C++ and OpenGL/GLUT. However, I've been having trouble programming the short time intervals allowed for input between movements. I've tried a few timing methods, and I ended up making a class for it (as you'll…
user3152847
4
votes
2 answers

How to update JLabel in Swing?

I am trying to use Swing Timer and I wanted to start from a very simple program. I have a window with text: "You have n seconds", where n changes from 10 to 0 every second. I know how to generate a window with text. And I understand how Timer works…
Roman
  • 124,451
  • 167
  • 349
  • 456
4
votes
1 answer

Objective C / iPhone: How to add a timer to let the text update?

I want to write an application that allow user to count down the time. The time will be displayed using label. I want to update the label every second, how can I do it? or which API is suitable for me to do this? thz in advance.
Tattat
  • 15,548
  • 33
  • 87
  • 138
4
votes
2 answers

Timer Queue in Windows Service

For a Windows Service, I need a timer to perform a certain task regularly. Of course, there are many options that seem superior to a timer (multithreading, calling method directly from the service's main thread), but they all have their…
LeRookie
  • 311
  • 3
  • 12
4
votes
1 answer

Script controls may not be registered before PreRender. when using timer control

I'm a newbie to ASP.net (vb), and i'm working with the timer controls. I've once again researched the answer to this and done as said (overloading prerender method). My problem is I have a master page which i've added a timer control, in order to…
user3741895
  • 41
  • 1
  • 5
4
votes
1 answer

how do I set the name of a system.timer dynamically

I have to create several timers dynamically but I need the name of them when they fire. Here is my code: timersDict = new Dictionary(); int i = 0; foreach (var msg in _messages.CurrentMessages) …
ErocM
  • 4,505
  • 24
  • 94
  • 161
4
votes
1 answer

Why Arduino uses interrupt every 1.024ms in millis function?

I am implementing a time counter on my atmega 328p. I looked on the implementation of arduino millis function and I am bit confused, why they use Timer Overflow Interrupt which is executed every 1.024 ms (freg = 16MHz, 64 prescaling), when they…
4
votes
4 answers

Execute for loop with time

I have a for loop like this for t = 0: 1: 60 // my code end I want to execute my code in 1st, 2nd, 3rd, ..., 60th seconds. How to do this? Also how can I run my code at arbitrary times? For example in 1st, 3rd and 10th seconds?
Dante
  • 611
  • 1
  • 7
  • 21
4
votes
1 answer

How to restart boost::timer::cpu_timer?

Looking at boost::timer::cpu_timer definition, I see that it doesn't seem to have any way to restart the timer. Is restarting a cpu_timer can only be done by recreating the timer object, or is there something I'm missing.
Elektito
  • 3,863
  • 8
  • 42
  • 72
4
votes
3 answers

Timer randomly doesn't fire

I have code that looks like this mTestModeMetadataTimer = new System.Threading.Timer(SomeTimerCallback, null, 1000, Timeout.Infinite); Stopwatch tmStopwatch = new Stopwatch(); private void SomeTimerCallback(object state) { // doing minimal…
Afcrowe
  • 129
  • 4
4
votes
6 answers

Does this code loop infinitely?

I have the following code, does this run an endless loop? I am trying to schedule something every minute and the console application should run continuously until I close it. class Program { static int curMin; static int lastMinute =…
Picflight
  • 3,832
  • 13
  • 61
  • 90
4
votes
3 answers

Pass System.Threading.Timer object reference to its callback function

is it possible to pass the System.Threading.Timer object reference to its callback function, something like this: System.Threading.Timer myTimer = new System.Threading.Timer(new TimerCallback(DoSomething), myTimer, 2000, Timeout.Infinite); Because…
Aremyst
  • 1,480
  • 2
  • 19
  • 33
4
votes
2 answers

Creating an Ajax timer in Ruby/Rails?

I'm trying to figure out the best solution to create a "game-round" timer in Ruby/Rails. Right now I'm just jotting notes, but in theory I'd like to set a 30 second timer on each round of game activity. Once the timer hits 0, the users turn is over.…
Nick L
  • 414
  • 3
  • 8
4
votes
2 answers

How to build a very-low resolution timer?

I need to implement a windows service that performs database import, and that once a month. The program receives data via e-mail, and will import them at the end of each month. Is there a better way than set the program to sleep for max_integer…
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442
4
votes
1 answer

Strange accuracy of QTimer with Windows 8

I'm using Qt 5.2.1 with Windows 8.1. I'm facing a strange behavior regarding QTimer accuracy on Windows 8.1. I'm starting a timer which is supposed to timeout every 20 milliseconds. To check that, I also use a QTime object to measure the elapsed…
Jérôme
  • 26,567
  • 29
  • 98
  • 120