System clock events

A

Andreas Håkansson

Hi,

Is there anyway to be notified with the system clock changes? I don't mean
when the user changes the settings, but each time (in my case) it swicthes
minute? I have some code I would like to run each time the minute changes of
the system clock. I could use a Timer object and set it's intervall to a
minute, but then it would only execute within a given minute of the system
clock, I want a trigger when it changes.

I dont mind using interop if thats what is required
 
B

Barry Kelly

Andreas Håkansson said:
Is there anyway to be notified with the system clock changes?

The system clock changes continuously many times per second. There
aren't separate events for per-minute changes.
I don't mean
when the user changes the settings, but each time (in my case) it swicthes
minute? I have some code I would like to run each time the minute changes of
the system clock. I could use a Timer object and set it's intervall to a
minute, but then it would only execute within a given minute of the system
clock, I want a trigger when it changes.

Your best bet is to look at the current time, and set the interval to
last you until just after the minute has changed. Every subsequent time
the event is triggered, repeat: recalibrate the interval based on the
current time so that the next event is due to happen just after the
minute has changed.

-- Barry
 
R

r norman

Hi,

Is there anyway to be notified with the system clock changes? I don't mean
when the user changes the settings, but each time (in my case) it swicthes
minute? I have some code I would like to run each time the minute changes of
the system clock. I could use a Timer object and set it's intervall to a
minute, but then it would only execute within a given minute of the system
clock, I want a trigger when it changes.

I dont mind using interop if thats what is required
Set a Timer object to once/second, then test the second value to see
if it is zero, or else test the minute value to see if it has changed.
Running the timer event processor 59 times when it is not needed seems
like a waste but is a completely negligible use of system time. It
works well and is simple. Of course if you need to know the even to
better than one second accuracy, you will have to check more
frequently.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top