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

Reliable timer in a console application

I am aware that in .NET there are three timer types (see Comparing the Timer Classes in the .NET Framework Class Library). I have chosen a threaded timer as the other types can drift if the main thread is busy, and I need this to be reliable. The…
John
  • 29,788
  • 18
  • 89
  • 130
113
votes
3 answers

Timertask or Handler

Let's say that I want to perform some action every 10 seconds and it doesn't necessarily need to update the view. The question is: is it better (I mean more efficient and effective) to use timer with timertask like here: final Handler handler = new…
keysersoze
  • 2,562
  • 4
  • 21
  • 22
112
votes
5 answers

Difference between std::system_clock and std::steady_clock?

What is the difference between std::system_clock and std::steady_clock? (An example case that illustrate different results/behaviours would be great). If my goal is to precisely measure execution time of functions (like a benchmark), what would be…
Vincent
  • 57,703
  • 61
  • 205
  • 388
111
votes
6 answers

Javascript: Call a function after specific time period

In JavaScript, How can I call a function after a specific time interval? Here is my function I want to run: function FetchData() { }
Shaggy
  • 5,422
  • 28
  • 98
  • 163
110
votes
17 answers

Timer function to provide time in nano seconds using C++

I wish to calculate the time it took for an API to return a value. The time taken for such an action is in the space of nanoseconds. As the API is a C++ class/function, I am using the timer.h to calculate the same: #include #include…
gagneet
  • 35,729
  • 29
  • 78
  • 113
110
votes
4 answers

How to stop the task scheduled in java.util.Timer class

I am using java.util.Timer class and I am using its schedule method to perform some task, but after executing it for 6 times I have to stop its task. How should I do that?
om.
  • 4,159
  • 11
  • 37
  • 36
109
votes
5 answers

Do C# Timers elapse on a separate thread?

Does a System.Timers.Timer elapse on a separate thread than the thread that created it? Lets say I have a class with a timer that fires every 5 seconds. When the timer fires, in the elapsed method, some object is modified. Lets say it takes a long…
user113164
  • 1,437
  • 5
  • 17
  • 17
109
votes
3 answers

Why there are 5 Versions of Timer Classes in .NET?

Why are there five timer classes in the .Net framework, namely the following: System.Timers.Timer System.Threading.Timer System.Windows.Forms.Timer System.Web.UI.Timer System.Windows.Threading.DispatcherTimer Why are there several versions of the…
Mohammed A. Fadil
  • 9,205
  • 7
  • 50
  • 67
108
votes
6 answers

Best Timer for using in a Windows service

I need to create some windows service which will execute every N period of time. The question is: Which timer control should I use: System.Timers.Timer or System.Threading.Timer one? Does it influence on something? I am asking because I heard many…
nKognito
107
votes
7 answers

Timer & TimerTask versus Thread + sleep in Java

I found similar questions asked here but there weren't answers to my satisfaction. So rephrasing the question again- I have a task that needs to be done on a periodic basis (say 1 minute intervals). What is advantage of using Timertask & Timer to do…
Keshav
  • 4,408
  • 8
  • 31
  • 50
106
votes
10 answers

Is gettimeofday() guaranteed to be of microsecond resolution?

I am porting a game, that was originally written for the Win32 API, to Linux (well, porting the OS X port of the Win32 port to Linux). I have implemented QueryPerformanceCounter by giving the uSeconds since the process start up: BOOL…
Bernard
  • 45,296
  • 18
  • 54
  • 69
103
votes
16 answers

C++ obtaining milliseconds time on Linux -- clock() doesn't seem to work properly

On Windows, clock() returns the time in milliseconds, but on this Linux box I'm working on, it rounds it to the nearest 1000 so the precision is only to the "second" level and not to the milliseconds level. I found a solution with Qt using the QTime…
hasen
  • 161,647
  • 65
  • 194
  • 231
102
votes
7 answers

Is there a Task based replacement for System.Threading.Timer?

I'm new to .Net 4.0's Tasks and I wasn't able to find what I thought would be a Task based replacement or implementation of a Timer, e.g. a periodic Task. Is there such a thing? Update I came up with what I think is a solution to my needs which is…
Jim
  • 4,910
  • 4
  • 32
  • 50
102
votes
4 answers

How to use QueryPerformanceCounter?

I recently decided that I needed to change from using milliseconds to microseconds for my Timer class, and after some research I've decided that QueryPerformanceCounter is probably my safest bet. (The warning on Boost::Posix that it may not works on…
Anonymous
  • 4,167
  • 11
  • 47
  • 52
102
votes
2 answers

Comparing Timer with DispatcherTimer

what is a difference between System.Windows.Forms.Timer() and System.Windows.Threading.DispatcherTimer() ? In which cases, we should use them? any best practices ?
paradisonoir
  • 2,892
  • 9
  • 30
  • 41