CancellationToken Class |
Namespace: Telogis.GeoBase.Concurrency
The CancellationToken type exposes the following members.
Name | Description | |
---|---|---|
CancellationToken |
Initializes the CancellationToken.
|
Name | Description | |
---|---|---|
IsCancellationRequested |
Indicates whether cancellation has been requested.
|
Name | Description | |
---|---|---|
Cancel |
Signals a request for cancellation.
| |
Dispose | Releases all resources used by the CancellationToken | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
// 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();