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

How to stop the Timer in android?

I'm developing an application which sends a message to a specific number in a specific period of time. The problem is that it continues sending that message after that period of time. How would I stop the timer after that specific time in order to…
Krishna
  • 4,892
  • 18
  • 63
  • 98
38
votes
4 answers

Countdown Timer Image GIF in Email

I recently received an emailer from Onnit Labs that included a Countdown Module Timer inside the emailer using a gif image. The emailer can be viewed here: https://www.onnit.com/emails/lastchance-historic/ The Image can be seen here: I looked into…
alvaram
  • 405
  • 1
  • 5
  • 7
37
votes
4 answers

Fortran intrinsic timing routines, which is better? cpu_time or system_clock

When timing a FORTRAN program i usually just use the command call cpu_time(t). Then i stumbled across call system_clock([count,count_rate,count_max]) which seems to do the same thing. However, in a more difficult manor. My knowledge of these come…
nickpapior
  • 752
  • 1
  • 8
  • 14
37
votes
1 answer

EJB3 + JEE6: What is a persistent Timer?

I'm just about to use the new EJB3 TimerService (as part of Java EE 6), and as usual, I'm impressed by the brevity of JavaDoc :) Do you know what is the effect of the persistent property of the TimerConfig object? JavaDoc TimerConfig says: The…
Hank
  • 4,597
  • 5
  • 42
  • 84
37
votes
3 answers

Android - Controlling a task with Timer and TimerTask?

I am currently trying to set up a WiFi Scan in my Android application that scans for WiFi access points every 30 seconds. I have used Timer and TimerTask to get the scan running correctly at the intervals which I require. However I want to be able…
Donal Rafferty
  • 19,707
  • 39
  • 114
  • 191
37
votes
3 answers

What is mach_absolute_time based on on iPhone

I use this code to keep track of last reboot: + (float) secondsSinceLastReboot{ return ((float)(mach_absolute_time())) * ((float)timebase.numer) / ((float)timebase.denom) / 1000000000.0f; } I assumed mach_absolute_time() was based on last…
Maxm007
  • 1,190
  • 2
  • 13
  • 21
36
votes
6 answers

Windows Service System.Timers.Timer not firing

I have a Windows service written in C# which is meant to perform a task every few minutes. I'm using a System.Timers.Timer for this but it doesn't ever appear to fire. I've looked at many different posts here on SO and elsewhere and I'm not seeing…
Joel Brown
  • 14,123
  • 4
  • 52
  • 64
36
votes
4 answers

Reschedule timer in android

How can I reschedule a timer. I have tried to cancel the timer/timertask and and schedule it again using a method. But its showing an exception error: Exception errorjava.lang.IllegalStateException: TimerTask is scheduled already Code I have used…
Dijo David
  • 6,175
  • 11
  • 35
  • 46
36
votes
5 answers

PowerShell show elapsed time

I have a script that kicks off an event and waits for the user to press any key to stop the script execution. I was trying to find a way to show a timer (how long the script has been running) while waiting for user input at Read-Host. Is there a way…
Jeff
  • 905
  • 2
  • 8
  • 17
35
votes
10 answers

Swift 3 - How to make timer work in background

i am trying to do an application which can make a timer run in background. here's my code: let taskManager = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(self.scheduleNotification), userInfo: nil, repeats: true) …
Cristina Reyes
  • 371
  • 1
  • 3
  • 5
35
votes
3 answers

Does a QTimer object run in a separate thread? What is its mechanism?

When I create a QTimer object in Qt 5, and start it using the start() member function, is a separate thread created that keeps track of the time and calls the timeout() function at regular intervals? For example, QTimer *timer = new…
GoodDeeds
  • 7,956
  • 5
  • 34
  • 61
35
votes
4 answers

How can I reproduce the race conditions in this python code reliably?

Context I recently posted a timer class for review on Code Review. I'd had a gut feeling there were concurrency bugs as I'd once seen 1 unit test fail, but was unable to reproduce the failure. Hence my post to code review. I got some great feedback…
doughgle
  • 827
  • 1
  • 9
  • 18
35
votes
5 answers

How can I perform a short delay in C# without using sleep?

I'm incredibly new to programming, and I've been learning well enough so far, I think, but I still can't get a grasp around the idea of making a delay the way I want. What I'm working on is a sort of test "game" thingy using a Windows forms…
user2706003
  • 361
  • 1
  • 3
  • 4
35
votes
4 answers

High resolution timer in .NET

I'd like to do some basic profiling of my code, but found that the DateTime.Now in C# only have a resolution of about 16 ms. There must be better time keeping constructs that I haven't yet found.
Mats Fredriksson
  • 19,783
  • 6
  • 37
  • 57
34
votes
5 answers

How to use Timer class to call a method, do something, reset timer, repeat?

I'm a Java beginner and have been futzing around with various solutions to this problem and have gotten myself kind of knotted up. I've tried with Threads and then discovered this Timer class and have messed around with it without success so far. …
chrisco
  • 834
  • 2
  • 10
  • 16