Visual studio feeds

All Visual Studio blogs in one place


Enter your email address:

Delivered by FeedBurner

Increase your website traffic with



Anti-spam: How many eyes has a typical person?

Follow us on FB


Async III: Cancellation

AddThis Social Bookmark Button
The previous posts in this series talked about the basics of async and exception handling. In this post we will take a look at cancellation and the beginnings of progress reporting.

For cancellation you can make use of a CancellationToken. This is an extra parameter that can be send to an asynchronous method call, most asynchronous methods you find in the .NET framework provide an overload with cancellation. You can extend your own asynchronous methods as well to take in a CancellationToken.

For progress reporting the IProgress interface can be used. This interface defines a Report
method that can be used to report progress from within an asynchronous method. Asynchronous calls again can define overloads that take in a IProgress interface.

Let's first take a look at cancellation.

protected async override void OnNavigatedTo(NavigationEventArgs e)
cts = new CancellationTokenSource();

await _restCaller.PublishHikeRequest(cts.Token);

var driverIds = await _restCaller.GetDrivers(cts.Token);

if (driverIds != null)
...(Read whole news on source site)

Home : Blog List : ProQ. Gitte Vermeiren : Async III: Cancellation