Game Development Reference
In-Depth Information
Table 37.1 Important Members of BackgroundWorker
Member
Description
CancelAsync
Invoking this method will cancel the progressing task.
CancellationPending
Invoking CancelAsync will set this property to true,
signifying that the user has requested cancellation of the task.
DoWork
This event is fired when RunWorkerAsync is invoked.
ProgressChanged
This event is fired when ReportProgress is invoked.
ReportProgress
Invoking this method will fire the ProgressChanged event,
updating the progress of the operation.
RunWorkerAsync
Executes the task asynchronously on a worker thread.
RunWorkerCompleted
This event is fired when the task is completed or cancelled,
or when an unhandled exception is thrown within the
DoWork event.
WorkerReportsProgress
Boolean property that specifies whether or not to report
progress.
WorkerSupportsCancellation
Boolean property that specifies whether or not the task can
be cancelled.
You can create BackgroundWorker programmatically or by dragging it onto your
form from the Components tab of the Visual Studio toolbox. The example in this
chapter shows programmatic instantiation and configuration. The following code
shows how to instantiate the BackgroundWorker .
backgroundWorker = new BackgroundWorker();
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.WorkerSupportsCancellation = true;
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler
(backgroundWorker_ProgressChanged);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler
(backgroundWorker_RunWorkerCompleted);
The DoWork event provides an instance of DoWorkEventArgs as a parameter, which
handles the input, output, and cancellation properties of the worker thread. Table
37.2 shows the properties of DoWorkEventArgs .
Search Nedrilad ::




Custom Search