Пример #1
0
 internal BackgroundWorker(ITextBuffer buffer, IBackgroundWork <TInput, TResults> work, bool createTimerNow)
 {
     _buffer          = buffer;
     _work            = work;
     _buffer.Changed += OnTextBufferChanged;
     _runTimer        = new Lazy <DispatcherTimer>(() =>
     {
         var timer = new DispatcherTimer(DispatcherPriority.Background)
         {
             Interval  = TimerDelay,
             IsEnabled = true
         };
         timer.Tick += ParseTimerTick;
         return(timer);
     });
     if (createTimerNow)
     {
         AutoCreateTimer();
     }
 }
Пример #2
0
        private void DoWork(object data)
        {
            backgroundWork = (IBackgroundWork)data;
            try
            {
                if (!doWorkAdded)
                {
                    doWorkDelegate += backgroundWork.DoBackgroundWork;
                    doWorkAdded     = true;
                }
                doWorkDelegate();
            }
            catch (WorkerCanceledException)
            {
                // This exception is throw only to stop the execution of the method delegated to doWorkDelegate
                if (WorkerCanceled != null)
                {
                    WorkerCanceled(backgroundWork, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                if (WorkerError != null)
                {
                    WorkerError(backgroundWork, new WorkerErrorEventArgs(ex));
                }
            }
            finally
            {
                if (WorkerCompleted != null)
                {
                    WorkerCompleted(backgroundWork, new EventArgs());
                }
                // If the operation was canceled by the user,
                // set the DoWorkEventArgs.Cancel property to true.
//				if (bw.CancellationPending)
//					e.Cancel = true;
            }
        }
        public void RunWorker(IBackgroundWork backgroundWork)
        {
            this.backgroundWork = backgroundWork;

            backgroundWorker = new BackgroundWorker();
            backgroundWorker.WorkerReportsProgress      = true;
            backgroundWorker.WorkerSupportsCancellation = true;
            backgroundWorker.DoWork             += backgroundWorker_DoWork;
            backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
//			backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged;

            if (BeforeRunWorker != null)
            {
                CancelEventArgs e = new CancelEventArgs();
                BeforeRunWorker(this, e);

                if (e.Cancel)
                {
                    return;
                }
            }

            backgroundWorker.RunWorkerAsync();
        }
 public void RunWorkerWithProgressDialog(IBackgroundWork backgroundWork, IControlView view, string caption, string text)
 {
     RunWorker(backgroundWork);
     ShowProgressDialog(view, caption, text);
 }
Пример #5
0
        public void RunWorker(IBackgroundWork backgroundWork)
        {
//			taskID = backgroundWork.TaskID;
            workerThread = new Thread(new ParameterizedThreadStart(DoWork));
            workerThread.Start(backgroundWork);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BackgroundWorkDriver"/> class.
 /// </summary>
 /// <param name="work">The work.</param>
 public BackgroundWorkDriver(IBackgroundWork work)
 {
     this.work = work;
     this.MaxBackgroundQueueCount = work.getMaxBackgroundQueueCount();
     this.DriverName = work.getDriverName();
 }