/// <summary>Starts execution of a background operation.</summary>
 /// <param name="argument">A parameter for use by the background operation to be executed in the <see cref="E:System.ComponentModel.BackgroundWorker.DoWork" /> event handler. </param>
 /// <exception cref="T:System.InvalidOperationException">
 ///   <see cref="P:System.ComponentModel.BackgroundWorker.IsBusy" /> is true. </exception>
 public void RunWorkerAsync(object argument)
 {
     if (this.IsBusy)
     {
         throw new InvalidOperationException("The background worker is busy.");
     }
     this.async = AsyncOperationManager.CreateOperation(this);
     BackgroundWorker.ProcessWorkerEventHandler processWorkerEventHandler = new BackgroundWorker.ProcessWorkerEventHandler(this.ProcessWorker);
     processWorkerEventHandler.BeginInvoke(argument, this.async, new SendOrPostCallback(this.CompleteWorker), null, null);
 }
Beispiel #2
0
 public void RunWorkerAsync(object argument)
 {
     if (this.isRunning)
     {
         throw new InvalidOperationException(SR.GetString("BackgroundWorker_WorkerAlreadyRunning"));
     }
     this.isRunning           = true;
     this.cancellationPending = false;
     this.asyncOperation      = AsyncOperationManager.CreateOperation(null);
     this.threadStart.BeginInvoke(argument, null, null);
 }
Beispiel #3
0
        /// <summary>Starts execution of a background operation.</summary>
        /// <param name="argument">A parameter for use by the background operation to be executed in the <see cref="E:System.ComponentModel.BackgroundWorker.DoWork" /> event handler. </param>
        /// <exception cref="T:System.InvalidOperationException">
        ///   <see cref="P:System.ComponentModel.BackgroundWorker.IsBusy" /> is true. </exception>
        public void RunWorkerAsync(object argument)
        {
            if (IsBusy)
            {
                throw new InvalidOperationException("The background worker is busy.");
            }
            async = AsyncOperationManager.CreateOperation(this);
            ProcessWorkerEventHandler processWorkerEventHandler = ProcessWorker;

            processWorkerEventHandler.BeginInvoke(argument, async, CompleteWorker, null, null);
        }
Beispiel #4
0
        public void RunWorkerAsync(object argument)
        {
            if (_isRunning)
            {
                throw new InvalidOperationException(SR.BackgroundWorker_WorkerAlreadyRunning);
            }

            _isRunning           = true;
            _cancellationPending = false;

            _asyncOperation = AsyncOperationManager.CreateOperation(null);
            Task.Factory.StartNew(
                (arg) => WorkerThreadStart(arg),
                argument,
                CancellationToken.None,
                TaskCreationOptions.DenyChildAttach,
                TaskScheduler.Default
                );
        }
 /// <summary>
 /// Creates a new async operation.
 /// </summary>
 /// <returns>
 /// An <see cref="AsyncOperation"/>.
 /// </returns>
 protected virtual AsyncOperation CreateAsyncOperation()
 {
     return(AsyncOperationManager.CreateOperation(null));
 }