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
31
votes
8 answers

react native show current time and update the seconds in real-time

I want to show the current time(MM/DD/YY hh:mm:ss) in react native app like a clock, and get update every seconds, I tried using new Date() and set it in state, but the time don't update unless I refresh the page. I also tried using setInterval…
inoutwhy
  • 624
  • 1
  • 6
  • 12
31
votes
3 answers

Creating a background timer to run asynchronously

I'm really struggling with this. I'm creating a winforms application in visual studio and need a background timer that ticks once every half hour - the purpose of this is to pull down updates from a server. I have tried a couple of different…
Mike Baxter
  • 6,868
  • 17
  • 67
  • 115
30
votes
3 answers

Elapsed time on a timer?

I have a really simple bit of code I use to test the response from proxy servers, I want to be able to start a timer and stop it and get the elapsed time it took for those to happen. However, I don't believe the code I have below is what I'm looking…
user222427
30
votes
7 answers

Pause CountDownTimer in Android when activity is not in front

I have an activity that uses a CountDownTimer that counts down from 10. How do I pause that timer when the activity is no longer in focus, like if the user get a call or something, then resume the timer when the user goes back to the activity? Is…
sfrider0
  • 363
  • 1
  • 3
  • 6
30
votes
4 answers

Objective C equivalent to javascripts setTimeout?

I was wondering whether there is a solution to raise an event once after 30 seconds or every 30 seconds in CocoaTouch ObjectiveC.
jantimon
  • 36,840
  • 23
  • 122
  • 185
29
votes
4 answers

Monotonically increasing time in JavaScript?

What’s the best way to get monotonically increasing time in JavaScript? I’m hoping for something like Java’s System.nanoTime(). Date() obviously won’t work, as it’s affected by system time changes. In other words, what I would like is for a <= b,…
danorton
  • 11,804
  • 7
  • 44
  • 52
29
votes
5 answers

How to clearInterval with unknown ID?

Say someone (evil) has set us a timer with setInterval, but we don't know its ID (we don't have the reference to the object, that setInterval is returning, nor its value) (function(){ setInterval(function(){console.log('pwned')}, …
mykhal
  • 19,175
  • 11
  • 72
  • 80
29
votes
7 answers

Synchronizing a timer to prevent overlap

I'm writing a Windows service that runs a variable length activity at intervals (a database scan and update). I need this task to run frequently, but the code to handle isn't safe to run multiple times concurrently. How can I most simply set up a…
JoshRivers
  • 9,920
  • 8
  • 39
  • 39
29
votes
9 answers

Timer.scheduledTimer does not work in Swift 3

I want to call the method func adjustmentBestSongBpmHeartRate() every 1.1 second. I used Timer, but it doesn't work. I have read the document and found a lot of sample code, it still does work! Is there anything I missed? timer =…
Jing Bian
  • 485
  • 2
  • 9
  • 14
29
votes
3 answers

Can Timers get automatically garbage collected?

When you use a Timer or a Thread that will just run for the entire lifetime of the program do you need to keep a reference to them to prevent them from being garbage collected? Please put aside the fact that the below program could have timer as a…
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
29
votes
2 answers

how to change timespan variable to a integer type?

I'm trying to convert timespan variable into an integer variable using 'parse'. I get an error that says: Format exception was unhandled: Input string was not in correct format This is the code is have : private void…
Aman Mehrotra
  • 373
  • 4
  • 7
  • 15
29
votes
5 answers

How to time a function in milliseconds without boost::timer

I am using boost 1.46 which does not include boost::timer, What other way can I time my functions. I am currently doing this: time_t now = time(0); time_t after = time(0); cout << after - now << endl; but it just gives the answer in…
Aly
  • 15,865
  • 47
  • 119
  • 191
29
votes
6 answers

Android: simple time counter

I have a simple program with one TextView and two Buttons: Button1 and Button2. Clicking on Button 1 will start a counter, increasing by 1 every 1 second and show result on TextView; clinking on Button 2 will stop it. Here is a part of my code for…
DavidNg
  • 2,826
  • 6
  • 32
  • 45
28
votes
5 answers

Javascript: Is it ok to call cleartimeout before settimeout?

I have a function that sets a timer, and calls itself back upon expiration of the timer. What I'd like to know is if it is bad practice to clear the timer at the top of the function. The reason for this is because I will be calling that function…
Kenny
  • 2,150
  • 2
  • 22
  • 30
28
votes
4 answers

Flutter - Blinking button

I need a call the user attention to a button. The first idea that came to mind is to add a blink animation. I really don't know how to do that, but I tried to make it work with the following code: Timer timer = new Timer(new Duration(seconds: 1), ()…
Notheros
  • 2,137
  • 9
  • 23
  • 34