Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, the design is terrible... but <em>if</em> you <em>need</em> to stick to it, you can set wait handles in a previous worker and wait for it in next. This is the minimal fix, still quite an abomination:</p> <pre><code>public void Start(object obj) { try { BackgroundWorker previousWorker = null; DataHolderClass previousWorkerParams = null; foreach (KeyValuePair&lt;string, Stream&gt; pair in this.CollectionOfFiles) { // signal event on previous worker RunWorkerCompleted event AutoResetEvent waitUntilCompleted = null; if (previousWorker != null) { waitUntilCompleted = new AutoResetEvent(false); previousWorker.RunWorkerCompleted += (o, e) =&gt; waitUntilCompleted.Set(); // start the previous worker previousWorker.RunWorkerAsync(previousWorkerParams); } Worker = new BackgroundWorker(); Worker.DoWork += (o, e) =&gt; { // wait for the handle, if there is anything to wait for if (waitUntilCompleted != null) { waitUntilCompleted.WaitOne(); waitUntilCompleted.Dispose(); } worker_DoWork(o, e); }; using (Stream stream = pair.Value) { primaryDocument = new Document(stream); DataHolderClass dataHolder = new DataHolderClass(); dataHolder.FileName = pair.Key; dataHolder.Doc = secondaryDocument; // defer running this worker; we don't want it to finish // before adding additional completed handler previousWorkerParams = dataHolder; } previousWorker = Worker; } if (previousWorker != null) { previousWorker.RunWorkerAsync(previousWorkerParams); } } catch (Exception ex) { // exception logic } finally { // complete logic } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload