Share via


BaseTaskForm.StartAsyncTask Method

Definition

Starts a task by using a worker thread.

Overloads

StartAsyncTask(DoWorkEventHandler, RunWorkerCompletedEventHandler)

Starts a task by using a worker thread, and configures the work-completed event handler.

StartAsyncTask(DoWorkEventHandler, RunWorkerCompletedEventHandler, MethodInvoker)

Starts a task by using a worker thread, and configures the work-completed and cancel-task event handlers.

StartAsyncTask(DoWorkEventHandler, RunWorkerCompletedEventHandler, MethodInvoker, Object)

Starts a task by using a worker thread, configures the work-completed and cancel-task event handlers, and passes an object to the task event handler.

StartAsyncTask(DoWorkEventHandler, RunWorkerCompletedEventHandler)

Starts a task by using a worker thread, and configures the work-completed event handler.

protected:
 void StartAsyncTask(System::ComponentModel::DoWorkEventHandler ^ doWorkHandler, System::ComponentModel::RunWorkerCompletedEventHandler ^ workCompletedHandler);
protected void StartAsyncTask (System.ComponentModel.DoWorkEventHandler doWorkHandler, System.ComponentModel.RunWorkerCompletedEventHandler workCompletedHandler);
member this.StartAsyncTask : System.ComponentModel.DoWorkEventHandler * System.ComponentModel.RunWorkerCompletedEventHandler -> unit
Protected Sub StartAsyncTask (doWorkHandler As DoWorkEventHandler, workCompletedHandler As RunWorkerCompletedEventHandler)

Parameters

doWorkHandler
DoWorkEventHandler

The DoWorkEventHandler delegate that represents the method that will handle the DoWork event.

workCompletedHandler
RunWorkerCompletedEventHandler

The RunWorkerCompletedEventHandler delegate that represents the method that will run when the work is complete.

Examples

The following example starts a task and provides a completion event handler.

void DoMyTask() {

    // note: StartAsyncTask calls StartTaskProgress();

    StartAsyncTask(new DoWorkEventHandler(OnWorkerMyJob),
                   new RunWorkerCompletedEventHandler(OnWorkerDoWorkCompleted));
}

Remarks

The StartAsyncTask method calls the StartTaskProgress method.

Only one task can run at a time. If StartAsyncTask is called before the previous StartAsyncTask call is complete, the previous task will be canceled.

Applies to

StartAsyncTask(DoWorkEventHandler, RunWorkerCompletedEventHandler, MethodInvoker)

Starts a task by using a worker thread, and configures the work-completed and cancel-task event handlers.

protected:
 void StartAsyncTask(System::ComponentModel::DoWorkEventHandler ^ doWorkHandler, System::ComponentModel::RunWorkerCompletedEventHandler ^ workCompletedHandler, System::Windows::Forms::MethodInvoker ^ cancelTaskHandler);
protected void StartAsyncTask (System.ComponentModel.DoWorkEventHandler doWorkHandler, System.ComponentModel.RunWorkerCompletedEventHandler workCompletedHandler, System.Windows.Forms.MethodInvoker cancelTaskHandler);
member this.StartAsyncTask : System.ComponentModel.DoWorkEventHandler * System.ComponentModel.RunWorkerCompletedEventHandler * System.Windows.Forms.MethodInvoker -> unit
Protected Sub StartAsyncTask (doWorkHandler As DoWorkEventHandler, workCompletedHandler As RunWorkerCompletedEventHandler, cancelTaskHandler As MethodInvoker)

Parameters

doWorkHandler
DoWorkEventHandler

The DoWorkEventHandler delegate that represents the method that will handle the DoWork event.

workCompletedHandler
RunWorkerCompletedEventHandler

The RunWorkerCompletedEventHandler delegate that represents the method that will run when the work is complete.

cancelTaskHandler
MethodInvoker

The MethodInvoker delegate that is called when the task is canceled.

Examples

The following example starts a task and provides completion and cancellation event handlers.

void DoMyTaskWithCancel() {

    // note: StartAsyncTask calls StartTaskProgress();

    StartAsyncTask(new DoWorkEventHandler(OnWorkerMyJob),
                   new RunWorkerCompletedEventHandler(OnWorkerDoWorkCompleted),
                   new MethodInvoker(OnWorkerCancel));
}

Remarks

The StartAsyncTask method calls the StartTaskProgress method.

Only one task can run at a time. If StartAsyncTask is called before the previous StartAsyncTask call is complete, the previous task will be canceled.

Applies to

StartAsyncTask(DoWorkEventHandler, RunWorkerCompletedEventHandler, MethodInvoker, Object)

Starts a task by using a worker thread, configures the work-completed and cancel-task event handlers, and passes an object to the task event handler.

protected:
 void StartAsyncTask(System::ComponentModel::DoWorkEventHandler ^ doWorkHandler, System::ComponentModel::RunWorkerCompletedEventHandler ^ workCompletedHandler, System::Windows::Forms::MethodInvoker ^ cancelTaskHandler, System::Object ^ argument);
protected void StartAsyncTask (System.ComponentModel.DoWorkEventHandler doWorkHandler, System.ComponentModel.RunWorkerCompletedEventHandler workCompletedHandler, System.Windows.Forms.MethodInvoker cancelTaskHandler, object argument);
member this.StartAsyncTask : System.ComponentModel.DoWorkEventHandler * System.ComponentModel.RunWorkerCompletedEventHandler * System.Windows.Forms.MethodInvoker * obj -> unit
Protected Sub StartAsyncTask (doWorkHandler As DoWorkEventHandler, workCompletedHandler As RunWorkerCompletedEventHandler, cancelTaskHandler As MethodInvoker, argument As Object)

Parameters

doWorkHandler
DoWorkEventHandler

The DoWorkEventHandler delegate that represents the method that will handle the DoWork event.

workCompletedHandler
RunWorkerCompletedEventHandler

The RunWorkerCompletedEventHandler delegate that represents the method that will run when the work is complete.

cancelTaskHandler
MethodInvoker

The MethodInvoker delegate that is called when the task is canceled.

argument
Object

The object passed to the DoWorkEventHandler delegate.

Examples

The following example starts a task, provides completion and cancellation event handlers, and passes an object to the task event handler.

void DoMyTaskWithCancel(Object myObj) {

    // note: StartAsyncTask calls StartTaskProgress();

    StartAsyncTask(new DoWorkEventHandler(OnWorkerMyJob),
                   new RunWorkerCompletedEventHandler(OnWorkerDoWorkCompleted),
                    new MethodInvoker(OnWorkerCancel),
                     myObj
                   );
}

Remarks

The StartAsyncTask method calls the StartTaskProgress method.

Only one task can run at a time. If StartAsyncTask is called before the previous StartAsyncTask call is complete, the previous task will be canceled.

Applies to