Namespace:
ESRI.ArcGISExplorer.Threading
Assembly:
ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.900 (2.0.0.900)
Syntax
Remarks
The BackgroundWorker class inherits from the .NET framework System.ComponentModel.Component class. It provides a similar programming experience to using the System.ComponentModel.BackgroundWorker class which is part of the .NET framework itself. Use the BackgroundWorker class to write add-ins for ArcGIS Explorer by making use of asynchronous operations on a worker thread, leaving the main user interface (UI) thread responsive.
You can create the BackgroundWorker programmatically or you can drag it onto a DockWindow or other Form from the Components tab of the Toolbox. If you create the BackgroundWorker in the Windows Forms Designer, it will appear in the Component Tray, and its properties will be displayed in the Properties window.
To execute a time-consuming operation on a worker thread:
- Create a BackgroundWorker object.
- Define an event handler for the DoWork event and associate it with the event on the BackgroundWorker object you created.
- Add code to the DoWork event handler to perform the worker thread operation.
- Call the RunWorkerAsync method on the BackgroundWorker object to start the worker thread operation.
Optionally you may also wish to:
- Pass information to the DoWork event handler by using the argument parameter, and then use this information from the Argument property of the DoWorkEventArgs parameter.
- Define an event handler for the ProgressChanged event and associate it with the event on the BackgroundWorker object. Call the ReportProgress method one or multiple times from the DoWork event handler to raise the ProgressChanged event, passing in progress and message information. Write code in the ProgressChanged event handler to update the user with progress information, using the Progress and Message properties of the ProgressChangedEventArgs, generally by showing and updating a non-modal dialog.
- Define an event handler for the RunWorkerCompleted event and associate it with the event on the BackgroundWorker object. Set the Result property of the DoWorkEventArgs parameter in the DoWork method with information about the result of this operation. Write code in the RunWorkerCompleted event handler to report a result to the user or otherwise update the user interface, using the Result property of the RunWorkerCompletedEventArgs.
Note: |
---|
You must be careful not to manipulate any user-interface objects in your DoWork event handler, which is called on a worker thread and not on the UI thread. Instead, communicate to the user interface through the arguments of the ProgressChanged and RunWorkerCompleted events. Consider the following rules for using a worker thread:
|
Inheritance Hierarchy
System..::.MarshalByRefObject
System.ComponentModel..::.Component
ESRI.ArcGISExplorer.Threading..::.BackgroundWorker
See Also
BackgroundWorker Members
BackgroundWorker Constructor
BackgroundWorker Methods
BackgroundWorker Properties
BackgroundWorker Events