Notified when system date has been changed.

  • Thread starter Thread starter Sin Jeong-hun
  • Start date Start date
S

Sin Jeong-hun

My application displays today's date on the form like;
Friday August 4, 2006

This information is determined at the form's constructor. But what
about the user has kept the form shown so long that the next day comes
( in this case, Saturday August 5, 2006)? One simple way is to check
the today's date periodically and if the date has been changed, then
update the date on the form. But this seems to be a waste. If the
interval is short, then the program will waste too much CPU, and if the
interval is long, then the date won't be updated immediately.

So, is there any event like "SystemDateChanged"? I tried to find it but
failed. Or do I have to use Win32 API to get notified?

Thanks.
 
Sin said:
My application displays today's date on the form like;
Friday August 4, 2006

This information is determined at the form's constructor. But what
about the user has kept the form shown so long that the next day comes
( in this case, Saturday August 5, 2006)? One simple way is to check
the today's date periodically and if the date has been changed, then
update the date on the form. But this seems to be a waste. If the
interval is short, then the program will waste too much CPU, and if the
interval is long, then the date won't be updated immediately.

So, is there any event like "SystemDateChanged"? I tried to find it but
failed. Or do I have to use Win32 API to get notified?

There's nothing relevant in Microsoft.Win32.SystemEvents, and it looks
like this is just a wrapper around the various broadcast WM_ Windows
messages, and I don't see one of those for the date just naturally
ticking over.

Rather than polling the time every second to see if the date has
changed, you could maybe note the time on startup (eg 4 pm), and set
something that notifies you (in this case) 8 hours later. Though this
could get flummoxed by daylight savings time...
 
You may be able to be notified of this change by using the following method:

protected override void WndProc(ref Message m)
{
System.Diagnostics.Debug.WriteLine(m);
base.WndProc(ref m);
}

I'm not sure what the exact message will be, but you should be see in the output window as you change the clock.

Hope this helps

Paul
 

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

Back
Top