Пример #1
0
        void _bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //remove callbacks
            _bgWorker.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(_bgWorker_RunWorkerCompleted);
            _bgWorker.ProgressChanged    -= new ProgressChangedEventHandler(_bgWorker_ProgressChanged);
            _bgWorker.DoWork             -= new DoWorkEventHandler(_bgWorker_DoWork);

            //close status window
            _bgStatusForm.Close();

            //cleanup
            _bgStatusForm = null;
            _bgWorker     = null;
        }
Пример #2
0
        public void ProcessMasterQueue(Queue <Queue <DistanceCalculationJob> > masterQueue)
        {
            if (masterQueue == null)
            {
                return;
            }
            _masterQueue = masterQueue;
            int totalNumberJobs = 0;

            Queue <Queue <DistanceCalculationJob> > .Enumerator e = masterQueue.GetEnumerator();
            while (e.MoveNext())
            {
                totalNumberJobs += e.Current.Count;
            }

            //check if there is actually work to do
            if (totalNumberJobs == 0)
            {
                return;
            }

            //setup gui
            _bgStatusForm = new BackgroundWorkerStatusForm(totalNumberJobs);

            //setup background worker
            _bgWorker = new BackgroundWorker();
            _bgWorker.WorkerReportsProgress      = true;
            _bgWorker.WorkerSupportsCancellation = false;
            _bgWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(_bgWorker_RunWorkerCompleted);
            _bgWorker.ProgressChanged           += new ProgressChangedEventHandler(_bgWorker_ProgressChanged);
            _bgWorker.DoWork += new DoWorkEventHandler(_bgWorker_DoWork);

            //start background worker
            _bgWorker.RunWorkerAsync();
            _bgStatusForm.ShowDialog(); //show in dialog mode, we will close it elsewhere
        }