Click here to view all files
 
Executes an operation on a worker thread.

Namespace:  ESRI.ArcGISExplorer.Threading
Assembly:  ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.900 (2.0.0.900)

Syntax

C#
public sealed class BackgroundWorker : Component
Visual Basic (Declaration)
Public NotInheritable Class BackgroundWorker _
	Inherits Component

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:

  1. Create a BackgroundWorker object.
  2. Define an event handler for the DoWork event and associate it with the event on the BackgroundWorker object you created.
  3. Add code to the DoWork event handler to perform the worker thread operation.
  4. 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:

  • ArcGIS Explorer objects are not thread safe; however you can serialize many ArcGIS Explorer objects and pass them from the UI thread to the worker thread (or vice-versa) and create new objects with the same state.
  • The ToXmlString and CreateFromXmlString methods are helper methods to perform the serialization simply. These methods are supported on Geometries, Graphics, MapItems, Symbols, and Viewpoints.
  • Use the arguments as described above to pass data passed between threads - you should not generally store member variables and access them from different threads. This type of usage is possible by reference to the .NET Framework help topics about thread synchronization but is considered an advanced usage and outside the scope of this documentation, and is still subject to the limitation of the ArcGIS Explorer objects not being thread-safe.

Inheritance Hierarchy

System..::.Object
  System..::.MarshalByRefObject
    System.ComponentModel..::.Component
      ESRI.ArcGISExplorer.Threading..::.BackgroundWorker

See Also

Relate Topics:
  BackgroundWorker Members
  BackgroundWorker Constructor
  BackgroundWorker Methods
  BackgroundWorker Properties
  BackgroundWorker Events
Created by Atop CHM to web converter,© 2009 all right reserved.