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
28
votes
1 answer

How to call an async task inside a timer?

I figured out how to use a repeat a normal method with a timer, and it worked fine. But now I have to use some async methods inside of this method, so I had to make it a Task instead of a normal method. This is the code I currently have now: public…
John Landon
  • 345
  • 1
  • 3
  • 10
28
votes
6 answers

System.Threading.Timer not firing after some time

I have a windows service application. And debugging it by running in console mode. Here http://support.microsoft.com/kb/842793 it is written that Timers.Timer has a bug and not firing in windows services. And workaround is to use Threading.Timer And…
AFgone
  • 1,172
  • 4
  • 16
  • 31
28
votes
5 answers

Qt5: How to wait for a signal in a thread?

Probably the title question is not very explicit. I am using Qt5 on Windows7. In a thread (QThread) at some point, in the "process()" function/method, I must wait for the "encrypted()" SIGNAL belonging to a QSslSocket I am using in this thread. Also…
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
28
votes
0 answers

How to use sys/time.h in windows?

I am using MSVS 2006 and trying to find time in microseconds in my program. I try to call sys/time.h in the header but this error is compiled. fatal error C1083: Cannot open include file: 'sys/time.h': No such file or directory Error executing…
Mazaya Jamil
  • 285
  • 1
  • 4
  • 7
28
votes
3 answers

How to detect when button pressed and released on android

I would like to start a timer that begins when a button is first pressed and ends when it is released (basically I want to measure how long a button is held down). I'll be using the System.nanoTime() method at both of those times, then subtract the…
Andy Thompson
  • 299
  • 1
  • 3
  • 9
28
votes
2 answers

Get elapsed time since application start

I am porting an app from ActionScript3.0 (Flex) to C# (WPF).AS3.0 has got a handy utility called getTimer() which returns time since Flash Virtual machine start in milliseconds.I was searching in C# through classes…
Michael IV
  • 11,016
  • 12
  • 92
  • 223
27
votes
3 answers

Jest setTimeout not pausing test

it('has working hooks', async () => { setTimeout(() => { console.log("Why don't I run?") expect(true).toBe(true) }, 15000) I've already reviewed this answer, Jest documentation, and several GitHub threads: Disable Jest setTimeout…
Nick
  • 581
  • 1
  • 7
  • 13
27
votes
4 answers

Can I use Task.Delay as a timer?

I want to execute some code on each second. The code I am using now is: Task.Run((Action)ExecuteSomething); And ExecuteSomething() is defined as below: private void ExecuteSomething() { Task.Delay(1000).ContinueWith( …
Sharun
  • 3,022
  • 6
  • 30
  • 59
27
votes
2 answers

Is it okay to attach async event handler to System.Timers.Timer?

I have already read the SO posts here and article here. I have a timer event that fires every once in a while and I want to do some asynchronous processing inside the handler, so something along the lines of: Timer timer = new…
LP13
  • 30,567
  • 53
  • 217
  • 400
27
votes
5 answers

iOS Run Code Once a Day

The idea behind this app is very simple: download a file. However this app will be for people who are not always within internet access range, so I need it to know that at, say 9:00 AM, to download a file to the hard drive. There will be a button…
Marcel Marino
  • 962
  • 3
  • 17
  • 34
26
votes
3 answers

length of System.currentTimeMillis

Does System.currentTimeMillis always returns a fixed length of value. In my windows Core2, it return a 13 digit long value. From its API: Returns the current time in milliseconds. Note that while the unit of time of the return value is a…
as.tek
  • 937
  • 3
  • 14
  • 20
26
votes
6 answers

Does the System.Windows.Forms.Timer run on a different thread than the UI?

I have a main thread that creates a form object which creates and sets a timer to run a function named updateStatus() every minute. But updateStatus() is also called by the main thread at several places. However, I am not clear about whether or not…
user186246
  • 1,857
  • 9
  • 29
  • 45
26
votes
4 answers

How scalable is System.Threading.Timer?

I'm writing an app that will need to make use of Timers, but potentially very many of them. How scalable is the System.Threading.Timer class? The documentation merely say it's "lightweight", but doesn't explain further. Do these timers get sucked…
Ben Collins
  • 20,538
  • 18
  • 127
  • 187
26
votes
2 answers

Thread-safety of System.Timers.Timer vs System.Threading.Timer

In this article: http://msdn.microsoft.com/en-us/magazine/cc164015.aspx the author states that System.Threading.Timer is not thread-safe. Since then this has been repeated on blogs, in Richter's book "CLR via C#", on SO, but this is never…
Pragmateek
  • 13,174
  • 9
  • 74
  • 108
26
votes
7 answers

Windows Service to run a function at specified time

I wanted to start a Windows service to run a function everyday at specific time. What method i should consider to implement this? Timer or using threads?
Ziyad Ahmad
  • 527
  • 2
  • 6
  • 18