Esempio n. 1
0
        public static BackgroundWorkerCancellationProvider Execute(
            Action <DoWorkContext> doWork,
            Action <WorkCompletedContext> workComplete,
            Action <WorkProgressContext> reportProgress = null)
        {
            var bw = new CancelableBackgroundWorker();

            bw.DoWork += (sender, args) => { doWork(new DoWorkContext((IBackgroundWorker)sender, args)); };

            bw.RunWorkerCompleted += (sender, args) =>
            {
                workComplete(new WorkCompletedContext((IBackgroundWorker)sender, args));
            };

            if (reportProgress != null)
            {
                bw.ProgressChanged += (sender, args) =>
                {
                    reportProgress(new WorkProgressContext((IBackgroundWorker)sender, args));
                };
                bw.WorkerReportsProgress = true;
            }

            bw.WorkerSupportsCancellation = true;
            bw.RunWorkerAsync();

            return(new BackgroundWorkerCancellationProvider {
                Cancel = () => bw.CancelAsync()
            });
        }
 public LoadBookmarksBgTask(BookmarksController controller)
 {
     this.controller = controller;
     this.bgWorker   = new CancelableBackgroundWorker <ObjectBuffer <Bookmark> >(this);
 }
Esempio n. 3
0
 public ListPatientsBgTask(OpenPatientDialog dialog)
 {
     this.dialog = dialog;
     bgWorker    = new CancelableBackgroundWorker <ObjectBuffer <PatientDataFile> >(this);
 }