예제 #1
0
파일: FormUtils.cs 프로젝트: 100052610/PFC
        public static void startNewWorkAsync(IWorker worker, IForm originForm, bool silent, bool blockInterface)
        {
            BackgroundWorker bw = new BackgroundWorker();
            bw.WorkerReportsProgress = true;

            // Tarea a realizar.
            bw.DoWork += new DoWorkEventHandler((o, args) => worker.doWork(o as BackgroundWorker, args));

            if (!silent){
                // Comportamiento a ejecutar cada vez que cambie el progreso.
                bw.ProgressChanged += new ProgressChangedEventHandler((o, args) => originForm.updateTaskProgress(args));
            }

            // Comportamiento a ejecutar cuando finalice por completo la tarea.
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler((o, args) => originForm.updateTaskCompleted(args));

            if (blockInterface)
            {
                FormUtils.enablingFormWorkingControls(originForm, false);
            }

            // Arranca la tarea en un Thread independiente del formulario de la aplicación, para no dejarla colgada.
            bw.RunWorkerAsync();
        }