Re: Timers
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Sat, 14 Jun 2008 17:45:10 -0700
On Sat, 14 Jun 2008 17:36:41 -0700, daveL <vettes_n_jets@xxxxxxxxx> wrote:
Im not explaining myself well , because im unsure how to approach this
so do i set the interval to x amount of milliseconds based on milliseconds
in a 24 hour period
then check if its the day i want
You could. But why not just set the interval to the number of milliseconds in a week?
also if time to run is involved do i set the timer to lets say hourly and
how to make it precise on the time required to run
How precise do you need it to be?
It seems to me your best bet is to determine the exact time in the future you want the timer to execute, calculate the difference between that exact time and "now", and then use the result of that as the timer delay for a one-shot timer.
Elapsed time calculation might look like:
DateTime dtEvent = /* initialized to some specific date/time */
TimeSpan tsDelay = dtEvent - DateTime.Now;
Then the milliseconds are "tsDelay.TotalMilliseconds". Assuming you're using a timer that requires setting in milliseconds, set this for the elapsed time for the timer and start the timer. It will fire when the elapsed time has expired. (Obviously for a timer class that accepts a TimeSpan value, you don't need to use the TotalMilliseconds property to convert to milliseconds :) ).
Each timer class has a slightly different syntax for configuring it as a one-shot timer, so without knowing what class you're using, it's not possible to say for sure what you would want to do. But, for example, the System.Timers.Timer class has an AutoReset property which, when set to false, causes the timer to fire just once. It won't fire again until you specifically start it again.
Finally, a week is a long time. Obviously you may want to include some means of re-enabling the timer in case your process exits and is restarted before the timer fires. This is just a special case of the above calculation, where the "specific date/time" is the same as it was before, but of course DateTime.Now returns a new value. :)
the thread is running perfect i just dont have it running like i need
yet....
No offense intended, but that sentence seems self-contradictory. :)
Pete
.
- Follow-Ups:
- Re: Timers
- From: daveL
- Re: Timers
- References:
- Timers
- From: daveL
- Re: Timers
- From: Peter Duniho
- Re: Timers
- From: daveL
- Re: Timers
- From: daveL
- Timers
- Prev by Date: Re: Timers
- Next by Date: Re: OperatingSystem Class for Remote Computer,...
- Previous by thread: Re: Timers
- Next by thread: Re: Timers
- Index(es):
Relevant Pages
|