Click or drag to resize

CancellationToken Class

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release
Propagates a request for a method call to be canceled before completion.
Inheritance Hierarchy
SystemObject
  Telogis.GeoBase.ConcurrencyCancellationToken

Namespace:  Telogis.GeoBase.Concurrency
Assembly:  geobase.net (in geobase.net.dll) Version: 4.99.0.0
Syntax
public class CancellationToken : IDisposable

The CancellationToken type exposes the following members.

Constructors
  NameDescription
Public methodCancellationToken
Initializes the CancellationToken.
Top
Properties
  NameDescription
Public propertyIsCancellationRequested
Indicates whether cancellation has been requested.
Top
Methods
  NameDescription
Public methodCancel
Signals a request for cancellation.
Public methodDispose
Releases all resources used by the CancellationToken
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks
Successfully canceling a calculation or query will cause an exception to be thrown, with the type of exception depending on the method being canceled. A successfully canceled routing method will throw a RouteCanceledException while a successfully canceled data query method will throw a DataQueryCanceledException.
Examples
The following example illustrates the use of the cancellation token to cancel a GetDirections calculation that takes more than 100 milliseconds to calculate. Under normal circumstances, calculations should be canceled when unusually slow; typically in the order of seconds or minutes, or when manually requested by a user.
C#
// Create route stops
RouteStop Arena = new RouteStop(new LatLon(34.0720, -117.4962));
RouteStop Depot = new RouteStop(new LatLon(34.1018, -118.2973));
RouteStop Mall = new RouteStop(new LatLon(33.845914, -118.232105));

// Create a route
Route myRoute = new Route();

// Set the route start location
myRoute.Start = Arena;

// Add the route stops
myRoute.AddStops(new RouteStop[] { Depot, Mall });

// Construct a Cancellation Token object.
Telogis.GeoBase.Concurrency.CancellationToken token = new Telogis.GeoBase.Concurrency.CancellationToken();

// Set a thread delay of a tenth of a second then signal a request for cancellation.
System.Threading.Thread cancelAfterDelay = new System.Threading.Thread(() => {
       System.Threading.Thread.Sleep(100);
       token.Cancel();
});

// Start the thread.
   cancelAfterDelay.Start();

// Abort the route calculation.
try { 
       myRoute.GetDirections(token); 
   }

// Catch the exception and display a message. 
catch (RouteCanceledException) {
   MessageBox.Show("The route computation was canceled");
}
cancelAfterDelay.Join();
See Also