backgroundworker

J

John Wright

I have a backgroundworker thread that I need to check some data for me every
6 hours or so. I can start the thread and do the check with great success,
but I only need this thread to check every six hours. I tried the timer
control, but that is clumbsy. I was wondering if I should use the thread to
keep track of the system time and subtract the time from last check and when
it hits 6 hours or greater run the process, or is there a better way? I
really don't want this thread just processing time when it is not needed.
Any suggestions?

John Wright
 
G

Guest

I have a backgroundworker thread that I need to check some data for me
every 6 hours or so. I can start the thread and do the check with
great success, but I only need this thread to check every six hours.
I tried the timer control, but that is clumbsy. I was wondering if I
should use the thread to keep track of the system time and subtract
the time from last check and when it hits 6 hours or greater run the
process, or is there a better way? I really don't want this thread
just processing time when it is not needed. Any suggestions?

You should use a timer - but .NET has 3 different timers (each with a
slightly different use):

http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/

Also you might want to build your app as a service - so that it can run
continously.

You may also want to track the last runtime - so if the app crashes, it can
pickup where it started up last.
 
C

Cor Ligthert [MVP]

John,

You mean that you want to use the instruction.

threading.thread.sleep(milliseconds).

As Spam Catcher already wrote. This is in my opinion a typical windowservice

I hope this helps,

Cor
 
J

John Wright

I got it. I just set the sleep as shown below. Then recall the DoWork sub
from the RunWorkerCompleted Sub. This gives me the six hours I need. A
windows service would be more combersome as we don't want to install
services on all the computers. This does great. Then I use delegates to
interact with the program. Thanks for the help.

John
System.Threading.Thread.Sleep(System.TimeSpan.FromHours(6))
 

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