There is a sequence for FORM(some UI) should get downloaded using service.
Currently, this download is in a BackgroundWorker Thread.
Now, since the performance is slow… We decided to categories the FORMS into 2 and start downloading parallely using another BackgroundWorker on top of the existing Thread.
Now, the scenario is the either of this BackgroundWorker should wait for other to complete.
So, how to implement it.
I tried with AutoResetEvent. but, i could not achieve this.
Any help is appreciated.
I don’t think that the scenario is really that one
BackgroundWorkershould wait for another. What you really want is to fire some UI event after (and only after) both of them complete. It’s a subtle but important difference; the second version is a lot easier to code.Note that those
objectreferences should be strongly-typed, I just usedobjectbecause I don’t know what you’re downloading.This is really all you need; the
RunWorkerCompletedevent runs in the foreground thread so you actually don’t need to worry about synchronization or race conditions in there. No need forlockstatements,AutoResetEvent, etc. Just use two member variables to hold the results, or two boolean flags if the result of either can actually benull.