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
49
votes
1 answer

Windows.Forms.Timer OR System.Threading.Timer

I have an application that runs many threads. Each thread should have a timer that checks for something in that thread's scope. My question is: Which timer I should use and what is the difference between them?
dlock
  • 9,447
  • 9
  • 47
  • 67
49
votes
8 answers

How long does my Python application take to run?

Basically, I want to be able to output the elapsed time that the application is running for. I think I need to use some sort of timeit function but I'm not sure which one. I'm looking for something like the following... START MY TIMER code for…
user1675111
  • 8,695
  • 4
  • 18
  • 14
48
votes
7 answers

How to create a high resolution timer in Linux to measure program performance?

I'm trying to compare GPU to CPU performance. For the NVIDIA GPU I've been using the cudaEvent_t types to get a very precise timing. For the CPU I've been using the following code: // Timers clock_t start, stop; float elapsedTime = 0; // Capture…
sj755
  • 3,944
  • 14
  • 59
  • 79
48
votes
11 answers

jQuery counter to count up to a target number

I'm trying to find out if anyone knows about an already existing jQuery plugin that will count up to a target number at a specified speed. For example, take a look at Google's number of MB of free storage on the Gmail homepage, under the heading…
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218
48
votes
3 answers

Free Rest API to retrieve current datetime as string (timezone irrelevant)

I am seeking a reliable REST API that can provide world time and time zone information across platforms. I need the current time as a string. I'd like it to return the result in under a second, regardless of the user's location worldwide. Among…
chadoh
  • 4,343
  • 6
  • 39
  • 64
48
votes
11 answers

C# Timer or Thread.Sleep

I am running a windows service and using a loop and Thread.Sleep to repeat a task, would it be better to use a timer method? If yes a code example would be great I am currently using this code to repeat int curMinute; int lastMinute =…
Adonis L
  • 1,679
  • 4
  • 20
  • 23
47
votes
7 answers

Is it necessary to dispose System.Timers.Timer if you use one in your application?

I am using System.Timers.Timer class in one of the classes in my application. I know that Timer class has Dispose method inherited from the parent Component class that implements IDisposable interface. Instances of the class below are created many…
Roman Shumikhin
  • 613
  • 2
  • 6
  • 10
46
votes
6 answers

High resolution timer with C++ and Linux?

Under Windows there are some handy functions like QueryPerformanceCounter from mmsystem.h to create a high resolution timer. Is there something similar for Linux?
okoman
  • 5,529
  • 11
  • 41
  • 45
46
votes
1 answer

Jquery/Ajax call with timer

I have a php page that echos out rows from a database. I want to call it via jquery/ajax every 30 seconds. But I also want to be able to call the page at any time so that if I add a record via the form, once the form submits I want the page via…
John
  • 9,840
  • 26
  • 91
  • 137
46
votes
4 answers

Android Timer schedule vs scheduleAtFixedRate

I'm writing an Android application that records audio every 10 minutes. I am using a Timer to do that. But what is the difference between schedule and scheduleAtFixedRate? Is there any performance benefit in using one over the other?
DXM
  • 1,249
  • 1
  • 14
  • 22
45
votes
5 answers

Cancellable threading.Timer in Python

I am trying to write a method that counts down to a given time and unless a restart command is given, it will execute the task. But I don't think Python threading.Timer class allows for timer to be cancelable. import threading def…
Ted
  • 723
  • 2
  • 10
  • 19
45
votes
11 answers

Most accurate timer in .NET?

Running the following (slightly pseudo)code produces the following results. Im shocked at how innacurate the timer is (gains ~14ms each Tick). Is there anything more accurate out there? void Main() { var timer = new…
maxp
  • 24,209
  • 39
  • 123
  • 201
45
votes
2 answers

javascript timer loop

I want to create a timer that once it reaches a certain point, the timer resets, and then starts over. Right now, I've got the loop set up, and as a test I want it to reset after 5000 ms (5 seconds). But the counter goes all haywire. WIP Demo here:…
stursby
  • 871
  • 2
  • 12
  • 23
44
votes
4 answers

System.Timers.Timer/Threading.Timer vs Thread with WhileLoop + Thread.Sleep For Periodic Tasks

In my application I have to send periodic heartbeats to a "brother" application. Is this better accomplished with System.Timers.Timer/Threading.Timer or Using a Thread with a while loop and a Thread.Sleep? The heartbeat interval is 1…
Alan
  • 45,915
  • 17
  • 113
  • 134
44
votes
6 answers

Get timer ticks in Python

I'm just trying to time a piece of code. The pseudocode looks like: start = get_ticks() do_long_code() print "It took " + (get_ticks() - start) + " seconds." How does this look in Python? More specifically, how do I get the number of ticks since…
andrewrk
  • 30,272
  • 27
  • 92
  • 113