Search code examples
c#multithreadingbackgroundworkeraccpac

Backgroundworker / Thread.Sleep on Search


I have a BackgroundWorker that I use on a Search. Two different Searches can be done, one to a SQL DB and another to an Accpac DB. To accommodate for slow execution time to the Accpac DB, I use Thread.Sleep. The problem is, when I do a search on my SQL DB, I give parameters stating it should only return active records. If I move the Thread.Sleep to accommodate for my Accpac search, then my SQL results return all records instead of Active only. If I move Thread.Sleep to accommodate for my SQL search, then there are issues on the Accpac search results returned.

Are there any other alternatives other than Thread.Sleep?


Solution

  • Sounds like you should look into Thread Synchronization classes such as WaitHandles. A ManualResetEvent would probably work pretty well for you.
    http://www.yoda.arachsys.com/csharp/threads/waithandles.shtml