Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1099
  • Last Modified:

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?
Eddie Shipman
Eddie Shipman
1 Solution
David L. HansenProgrammer AnalystCommented:
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.
Eddie ShipmanAll-around developerAuthor Commented:
Actually, we've found the problem and are correcting it now.
Thanks for taking a look at this.

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now