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
101
votes
3 answers

Proper way to implement a never ending task. (Timers vs Task)

So, my app needs to perform an action almost continuously (with a pause of 10 seconds or so between each run) for as long as the app is running or a cancellation is requested. The work it needs to do has the possibility of taking up to 30…
Josh
  • 2,083
  • 5
  • 23
  • 28
91
votes
6 answers

How to access the HttpServerUtility.MapPath method in a Thread or Timer?

I use a System.Timers.Timer in my Asp.Net application and I need to use the HttpServerUtility.MapPath method which seems to be only available via HttpContext.Current.Server.MapPath. The problem is that HttpContext.Current is null when the…
Costo
  • 5,940
  • 8
  • 33
  • 35
90
votes
32 answers

Error 1053 the service did not respond to the start or control request in a timely fashion

I have created and installed a service a couple of times. Initially it was working fine, but after some changes in the service Code it start giving the error when I restart the service in Services.msc : Error 1053: the service did not respond to…
Neeraj Verma
  • 2,174
  • 6
  • 30
  • 51
89
votes
6 answers

Best timing method in C?

What is the best way to time a code section with high resolution and portability? /* Time from here */ ProcessIntenseFunction(); /* to here. */ printf("Time taken %d seconds %d milliseconds", sec, msec); Is there a standard library that would have…
lillq
  • 14,758
  • 20
  • 53
  • 58
86
votes
7 answers

C# - how do you stop a timer?

I know it sounds stupid, but I've tried everything to stop a timer, but the timer won't stop. I'm working on a game and i would appreciate if someone could tell me how to stop a timer.
di0xide007
  • 881
  • 1
  • 6
  • 4
86
votes
6 answers

Create a simple 10 second countdown

I would like a line that says: Your download will begin in (10, 9, 8, etc. Beginning on page load) seconds. I already have the 10 second download text set up, and I have looked at other stackoverflow posts. They all include CSS, and Jquery. I would…
85
votes
4 answers

How do I schedule a task to run at periodic intervals?

I was trying some codes to implement a scheduled task and came up with these codes . import java.util.*; class Task extends TimerTask { int count = 1; // run is a abstract method that defines task performed at scheduled time. public…
Manish Basdeo
  • 6,139
  • 22
  • 68
  • 102
84
votes
10 answers

How to time an operation in milliseconds in Ruby?

I'm wishing to figure out how many milliseconds a particular function uses. So I looked high and low, but could not find a way to get the time in Ruby with millisecond precision. How do you do this? In most programming languages its just something…
Earlz
  • 62,085
  • 98
  • 303
  • 499
83
votes
4 answers

Why does a System.Timers.Timer survive GC but not System.Threading.Timer?

It appears that System.Timers.Timer instances are kept alive by some mechanism, but System.Threading.Timer instances are not. Sample program, with a periodic System.Threading.Timer and auto-reset System.Timers.Timer: class Program { static void…
Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810
83
votes
14 answers

C++ Cross-Platform High-Resolution Timer

I'm looking to implement a simple timer mechanism in C++. The code should work in Windows and Linux. The resolution should be as precise as possible (at least millisecond accuracy). This will be used to simply track the passage of time, not to…
Amish Programmer
  • 2,051
  • 3
  • 19
  • 22
82
votes
3 answers

Executing JavaScript after X seconds

I am building a interstitial page, using
and JavaScript, really simple script but neat. Everything is working, but I also would like to close the div's after a few seconds (like 10 seconds, for example). Here what I have so far: I have two…
Paulo Capelo
  • 1,062
  • 1
  • 9
  • 13
79
votes
7 answers

Can Stopwatch be used in production code?

I need an accurate timer, and DateTime.Now seems not accurate enough. From the descriptions I read, System.Diagnostics.Stopwatch seems to be exactly what I want. But I have a phobia. I'm nervous about using anything from System.Diagnostics in…
Adrian
  • 793
  • 1
  • 5
  • 5
79
votes
16 answers

Is there a more accurate way to create a Javascript timer than setTimeout?

Something that has always bugged me is how unpredictable the setTimeout() method in Javascript is. In my experience, the timer is horribly inaccurate in a lot of situations. By inaccurate, I mean the actual delay time seems to vary by 250-500ms more…
Dan Herbert
  • 99,428
  • 48
  • 189
  • 219
76
votes
1 answer

DropWizard Metrics Meters vs Timers

I am learning the DropWizard Metrics library (formerly Coda Hale metrics) and I am confused as to when I should be using Meters vs Timers. According to the docs: Meter: A meter measures the rate at which a set of events occur and: Timer: A timer…
smeeb
  • 27,777
  • 57
  • 250
  • 447
75
votes
12 answers

how to pass parameters of a function when using timeit.Timer()

This is the outline of a simple program # some pre-defined constants A = 1 B = 2 # function that does something critical def foo(num1, num2): # do something # main program.... do something to A and B for i in range(20): # do something to A…
CppLearner
  • 16,273
  • 32
  • 108
  • 163