private void StartProgressControl(BackgroundWorker worker, ProgressControl pc)
 {
     if (syncQueue.Count > 0)
     {
         WorkerArguments args = (WorkerArguments)syncQueue.Dequeue();
         if (args != null)
         {
             pc.Initialize();
             pc.SetPhaseLabel(args.Phase);
             worker.RunWorkerAsync(args);
         }
     }
 }
 private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     ReportInfo r = (ReportInfo)e.UserState;
     progressctrl = mapWorkerToProgressBar[(BackgroundWorker)sender] as ProgressControl;
     if (progressctrl != null)
     {
         progressctrl.SetProgressValue(r.inc);
         progressctrl.SetStatusLabel(r.status);
     }
 }
        private void InitializeWorkers(int nMaxParallel)
        {
            mapWorkerToProgressBar = new Hashtable(nMaxParallel);

            for (int i = 0; i < nMaxParallel; i++)
            {
                worker = new BackgroundWorker();
                progressctrl = new ProgressControl();
                this.layoutPanel.Controls.Add(progressctrl);

                worker.WorkerReportsProgress = true;
                worker.WorkerSupportsCancellation = true;
                worker.DoWork += new DoWorkEventHandler(worker_DoWork);
                worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
                worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

                mapWorkerToProgressBar.Add(worker, progressctrl);
            }

            Rectangle bounds = this.Bounds;
            this.SetBounds(bounds.Left, bounds.Top - panel1.Height / 2, bounds.Width, bounds.Height + panel1.Height);
        }