Example of using Timer and BackgroundWorker together

I have an app that isn't working correctly. I have intervals that I want the BackgroundWorkers to run but they are not "sleeping" for the full interval.

I have three BackgroundWorkers (dropped on the form) that I need to run at specified intervals.

    Dim INTERVAL_ProcessMessages As Integer = 10000
    Dim INTERVAL_PatientRequests As Integer = 180000
    Dim INTERVAL_VisitRequests As Integer = 180000

We call the Sleep method of the Thread in each of the DoWork events like this:

But, we are logging the work done in the DoWork and have found that the bwVisitRequests_DoWork is running
every 3-15 seconds, here is a copy of our log showing the VisitRequests:
Message_Type  Message_ID                    Request_Time
GETDATEVISITS GETDATEVISITS_20081113061959 11/13/2008 6:19:59 AM
GETDATEVISITS GETDATEVISITS_20081113062005 11/13/2008 6:20:05 AM
GETDATEVISITS GETDATEVISITS_20081113062028 11/13/2008 6:20:28 AM
GETDATEVISITS GETDATEVISITS_20081113062030 11/13/2008 6:20:30 AM
GETDATEVISITS GETDATEVISITS_20081113062033 11/13/2008 6:20:33 AM
GETDATEVISITS GETDATEVISITS_20081113062114 11/13/2008 6:21:14 AM
GETDATEVISITS GETDATEVISITS_20081113062116 11/13/2008 6:21:16 AM
GETDATEVISITS GETDATEVISITS_20081113062120 11/13/2008 6:21:20 AM
GETDATEVISITS GETDATEVISITS_20081113062134 11/13/2008 6:21:34 AM
GETDATEVISITS GETDATEVISITS_20081113062152 11/13/2008 6:21:52 AM
GETDATEVISITS GETDATEVISITS_20081113062159 11/13/2008 6:21:59 AM
GETDATEVISITS GETDATEVISITS_20081113062222 11/13/2008 6:22:22 AM
GETDATEVISITS GETDATEVISITS_20081113062247 11/13/2008 6:22:47 AM
GETDATEVISITS GETDATEVISITS_20081113062309 11/13/2008 6:23:09 AM
GETDATEVISITS GETDATEVISITS_20081113062327 11/13/2008 6:23:27 AM
GETDATEVISITS GETDATEVISITS_20081113062332 11/13/2008 6:23:32 AM
GETDATEVISITS GETDATEVISITS_20081113062338 11/13/2008 6:23:38 AM

We want to use Timers to handle the intervals but still use the BackgroundWorkers to do the work without
doing too much to modify the code.

Any ideas on how to do this?
LVL 27
Eddie ShipmanAll-around developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David L. HansenCEOCommented:
You do understand that timers are not threads.  You are still working with a logic that moves step by step in a single thread.  A timer will just interupt your logic flow and do stuff then return back to the original logic flow.  The fact that you are using several timers hints at an assupption of multi-thread logic (I may be mistaken..if so sorry).  But at any rate, it is important to keep threading principals strait in your head when working with timers.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eddie ShipmanAll-around developerAuthor Commented:
Actually, we've found the problem and are correcting it now.
Thanks for taking a look at this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.