Esempio n. 1
0
 /// <inheritdoc />
 public virtual void Run(TaskWithProgress task)
 {
     Run(ProgressMonitor =>
     {
         task(ProgressMonitor);
         return(0);
     });
 }
Esempio n. 2
0
        /// <inheritdoc />
        public virtual T Run <T>(TaskWithProgress <T> task)
        {
            IProgressMonitorPresenter presenter = GetPresenter();

            using (var progressMonitor = new ObservableProgressMonitor())
            {
                presenter.Present(progressMonitor);
                progressMonitor.ThrowIfCanceled();
                T result = task(progressMonitor);
                progressMonitor.ThrowIfCanceled();
                return(result);
            }
        }
        public T Run <T>(TaskWithProgress <T> task)
        {
            IProgressMonitorPresenter presenter = new ProgressMonitorPresenter(_executionRecorder);

            using (var progressMonitor = new ObservableProgressMonitor())
            {
                presenter.Present(progressMonitor);
                progressMonitor.ThrowIfCanceled();
                T result = task(progressMonitor);
                progressMonitor.ThrowIfCanceled();
                return(result);
            }
        }
Esempio n. 4
0
        private void RunWithProgress(TaskWithProgress task, ref bool canceled)
        {
            try
            {
                progressMonitorProvider.Run(progressMonitor =>
                {
                    try
                    {
                        bool wasCanceled;
                        lock (cancelationSyncRoot)
                        {
                            wasCanceled = isCanceled;
                            cancelableProgressMonitor = progressMonitor;
                        }

                        if (wasCanceled)
                        {
                            progressMonitor.Cancel();
                        }
                        else
                        {
                            task(progressMonitor);
                        }
                    }
                    finally
                    {
                        lock (cancelationSyncRoot)
                            cancelableProgressMonitor = null;
                    }
                });
            }
            catch (OperationCanceledException)
            {
                canceled = true;
            }
        }