c# - Waiting for either of these BackgroundWorker to complete -
There is a sequence for the farm (some UI) should download using the service Currently, this download is in the background worker thread is. Now, since the performance is slow ... we decided to form categories in 2 and started parallel by using another background player on the current thread.
Now, the scenario should be either of this backgroundworker to wait for others to complete, then how to implement it.
I tried with an AutoSetset
I do not think that the scenario actually Is that a backgroundworker
should wait for another. Do you really want to complete completely after some UI event (and after) This is a subtle but important difference; The second version is very easy to code.
Public category Form 1: Form {Private object download 1 result; Private Object Downloads 2 Results; Private Zero BeginDownload () {// The next two rows are only required if it is downloaded multiple times 1 Result = Faucet; Download 2 results = Faucet; BwDownload1.RunWorkerAsync (); BwDownload2.RunWorkerAsync (); } Private Zero contains bwDownload1_RunWorker (Object Sender, RunWorkerCompletedEventArgs e) {download1Result = e.Result; If (download2Result! = Null) DisplayResults (); } Private Zero Download BW 2_Respondent Complete (Object Sender, Runwalker Comprehensive Avant-erg E) {download2Result = e.Result; If (download 1 result! = Tap) displayResults (); } Do something with Private Zero DisplayResults () {// Download1Result and download2Result}}
Note that those objects
references should be typed strongly, I just do object
because I do not know what you're downloading.
It really needs you; The forwarding thread runs the Runawalker Composite
event, so you do not really need to worry about synchronization or running conditions. There is no need for lock
statements, AutoResetEvent , etc., use two member variables for the result, or two boolean flags if the result is actually Null
.
Comments
Post a Comment