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
75
votes
7 answers

Python loop to run for certain amount of seconds

I have a while loop, and I want it to keep running through for 15 minutes. it is currently: while True: #blah blah blah (this runs through, and then restarts. I need it to continue doing this except after 15 minutes it exits the loop) Thanks!
oam811
  • 755
  • 1
  • 5
  • 6
72
votes
8 answers

Start and stop a timer PHP

I need some information regarding starting and stopping a timer in PHP. I need to measure the elapsed time from the start of my .exe program (I'm using exec() function in my php script) until it completes the execution and display the time it took…
125369
  • 3,547
  • 20
  • 52
  • 70
72
votes
11 answers

Reliably stop System.Threading.Timer?

Well I've searched a lot for a solution to this. I'm looking for a clean and simple way to prevent the callback method of a System.Threading.Timer from being invoked after I've stopped it. I can't seem to find any, and this has led me, on occassion,…
JayPea
  • 9,551
  • 7
  • 44
  • 65
72
votes
2 answers

How to do a timer in Angular 5

I'm using Angular 5. I want to know how can I start timing when a 'play' button is pressed, in order to know how much time has passed since I clicked. I'd also like to know if it's possible to stop the timer and then be able to continue with the…
Samuel
  • 816
  • 1
  • 7
  • 13
70
votes
10 answers

How to fire timer.Elapsed event immediately

I'm using the System.Timers.Timer class to create a timer with an Timer.Elapsed event. The thing is the Timer.Elapsed event is fired for the first time only after the interval time has passed. Is there a way to raise the Timer.Elapsed event right…
Otiel
  • 18,404
  • 16
  • 78
  • 126
70
votes
16 answers

C# run a thread every X minutes, but only if that thread is not running already

I have a C# program that needs to dispatch a thread every X minutes, but only if the previously dispatched thread (from X minutes) ago is not currently still running. A plain old Timer alone will not work (because it dispatches an event every X…
Keith Palmer Jr.
  • 27,666
  • 16
  • 68
  • 105
69
votes
3 answers

Why are .NET timers limited to 15 ms resolution?

Note that I'm asking about something that will call a callback function more often than once every 15 ms using something like System.Threading.Timer. I'm not asking about how to accurately time a piece of code using something like…
Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
69
votes
5 answers

How to find out if a Timer is running?

If I have an instance of a System.Timers.Timer that has a long interval - say 1 minute, how can I find out if it is started without waiting for the Tick?
George Mauer
  • 117,483
  • 131
  • 382
  • 612
68
votes
4 answers

I want to load another HTML page after a specific amount of time

I have one html page "form1.html" which has an animated image. I want to load another page "form2.html" after 5 seconds. How do I do this?
ash9209
  • 1,018
  • 2
  • 9
  • 16
67
votes
11 answers

Wait some seconds without blocking UI execution

I would like to wait some seconds between two instruction, but WITHOUT blocking the execution. For example, Thread.Sleep(2000) it is not good, because it blocks execution. The idea is that I call a method and then I wait X seconds (20 for example)…
user3376691
  • 789
  • 1
  • 5
  • 4
66
votes
6 answers

iOS perform action after period of inactivity (no user interaction)

How can I add a timer to my iOS app that is based on user interaction (or lack thereof)? In other words, if there is no user interaction for 2 minutes, I want to have the app do something, in this case navigate to the initial view controller. If at…
BobbyScon
  • 2,537
  • 2
  • 23
  • 32
65
votes
6 answers

Compare using Thread.Sleep and Timer for delayed execution

I have a method which should be delayed from running for a specified amount of time. Should I use Thread thread = new Thread(() => { Thread.Sleep(millisecond); action(); }); thread.IsBackground = true; thread.Start(); Or Timer timer = new…
63
votes
8 answers

Call jQuery Ajax Request Each X Minutes

How can I call an Ajax Request in a specific period of time? Should I use Timer Plugin or does jQuery have a plugin for this?
Shahin
  • 12,543
  • 39
  • 127
  • 205
62
votes
9 answers

What is the equivalent of javascript setTimeout in Java?

I need to implement a function to run after 60 seconds of clicking a button. Please help, I used the Timer class, but I think that that is not the best way.
62
votes
12 answers

How to create a JQuery Clock / Timer

I have a simple quiz application and I want display a nice timer / clock at the top of the page which shows the user how long they've been going for. (If I could somehow show them a timer for Total Quiz Time and also a second one for This Question…
Ganesh Shankar
  • 4,826
  • 8
  • 43
  • 56