How to wait for background worker to finish processing?

前端 未结 5 684
闹比i
闹比i 2021-01-19 17:07

I have 3 background workers each processing a channel of a 24-bit Bitmap image (Y, Cb, Cr). The processing for each 8-bit image takes several seconds and they might not com

5条回答
  •  独厮守ぢ
    2021-01-19 17:46

    Building on the answer from Renuiz, I would do it this way:

    private object lockObj;
    
    private void backgroundWorkerN_RunWorkerCompleted(
        object sender, 
        RunWorkerCompletedEventArgs e)
    {
        lock (lockObj)
        {
            y = true;
            if (cb && cr) // if cb and cr flags are true - 
                          // other backgroundWorkers finished work
            {
                someMethodToDoOtherStuff();
            }
        }
    }
    

提交回复
热议问题