Sunday, September 28, 2014

Cancelling an async task without a CancellationToken

I have seen a number of examples of how to write asynchronous tasks which include the CancellationToken to allow them to be cancelled. My problem is finding a simple way to cancel a method such as:



MapLocationFinderResult result =
await MapLocationFinder.FindLocationsAsync(
addressToGeocode,
hintPoint,
resultCount);

This call is made inside an async method which is called from an event handler.


I want to present a busy indicator and a CANCEL button on the screen but I need a way to cancel the "await" when the button is clicked (and of course to know it has been cancelled so I can prevent some other actions from occurring).


If I work my way far enough through the inheritances then I eventually come to a Cancel method in the IAsyncInfo interface but I don't know if or how this can be used.


Any help would be appreciated.




Woke up one day and realised reality television had destroyed too many brain cells so started writing App's to re-start my brain.


No comments:

Post a Comment