Timers

D

daveL

I want to Start a process in a Service
once a Week

Whats the Best Way to Handle this

I have A completed Service with Threading Manager
But I dont know the Best way to Start a Process
on a Given Day...only once on That Day if Success
if Failure ..then Try Again

Tks
DaveL
 
D

daveL

I am Using System.Timer
Where im having a problem is
Iim not sure how to
go about having this fire once a week and only run once
on a specified Day

Any advice
Thanks DaveL
 
D

daveL

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

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

the thread is running perfect i just dont have it running like i need
yet....

i hope the above helps..
Thanks DaveL

much appriciated
 
D

daveL

about my last sentence....lol I know...
what i meant was i just set the timer to 30 seconds while testing the
threading
so i can make sure all is running correctly, stored procs , processing,
updating etc

now i need to re think the timers on running the way they need to run

1 time once a week at a given time....

I thank you very much for your time and effort
DaveP

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
 

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

Top