471,337 Members | 998 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Timer.Elapsed on Date Change (millsecs)

ugh. Okay, I need to figure out the number of milliseconds between
DateTime.Now and the end of the day so that I can make changes based on
the date roll-over. I need to implement a Timer so that I can process
things on the Timer.Elapsed event that would happen right at the date
change (unless there is a better suggestion to implement an event on
the date change). DateTime isn't so friendly to this calculation.
Please, any suggestions are welcome. Preferably something efficient
and Threadsafe. VB.net is fine but C# is my current language.

Cheers and Thank you. This is bugging me!

Russ

Aug 10 '05 #1
3 1714
It all depends on what you mean by 'right at the date change'.

If you mean within a few seconds of midnight then it is relatively easy.

Create a timer with an interval of, say, 10 seconds.

Directly before starting the timer, store Now in a variable with scope
sufficient so that the timer elapsed event handler can see it.

In the timer elapsed event handler if the date part of Now is different than
the date part of the stored value then the date has changed.
<rh****@axys.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
ugh. Okay, I need to figure out the number of milliseconds between
DateTime.Now and the end of the day so that I can make changes based on
the date roll-over. I need to implement a Timer so that I can process
things on the Timer.Elapsed event that would happen right at the date
change (unless there is a better suggestion to implement an event on
the date change). DateTime isn't so friendly to this calculation.
Please, any suggestions are welcome. Preferably something efficient
and Threadsafe. VB.net is fine but C# is my current language.

Cheers and Thank you. This is bugging me!

Russ

Aug 10 '05 #2
Thanks for the suggestion. A friend sent me this:

public long MillisecsToNextDay()
{

DateTime dteCurrent = DateTime.Now;
DateTime dteTomorrow = DateTime.Today.AddDays(1);

long lgnValue = dteTomorrow.Ticks - dteCurrent.Ticks;

return (lgnValue/1000);

}
You could also use the number of Ticks in a day (86400000000) and do
something like this:

86400000000 - DateTime.Now.Ticks

Cheers!
Russ

Aug 10 '05 #3
oops. scratch the last part of that suggestion (86400000000 -
DateTime.Now.Ticks )...

Russ

Aug 10 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mr. B | last post: by
3 posts views Thread by jam | last post: by
2 posts views Thread by Besta | last post: by
7 posts views Thread by Mike Eaton | last post: by
11 posts views Thread by Philip Wagenaar | last post: by
2 posts views Thread by zamir.khan | last post: by
4 posts views Thread by Liverpool fan | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.