473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1827
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mr. B | last post by:
My current app has a timer that I kick ON in my Form1_Load as follows: ' Set Up the Timer Function Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second t.Enabled = True ' False to Turn OFF...
3
by: jam | last post by:
Dear all, I am wrtiing a console application and doing some test on timer, the below is my sample code I got from some site, but I cannot make it work... Error is 'System.Timers.Timer' does not...
2
by: Besta | last post by:
Hello all, I am having trouble creating a windows service with a timer. Everything seems to go ok but the elapsed event does not fire.Can anyone shed any light on this, may be something simple as...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
7
by: Mike Eaton | last post by:
Hi All, I have a simple application that allows users to clock in and out and stores the data for use by the payroll department. It spends most of its life as a tray icon and when the user...
11
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the...
3
by: rhaley | last post by:
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...
2
by: zamir.khan | last post by:
Hello all, New to the groups, sorry if this the wrong forum/etiquette. I am coding a c++ application that requires the use of a timer-triggered event handler. I decided to use the timer provided...
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.