O'Reilly logo

Windows Presentation Foundation 4.5 Cookbook by Pavel Yosifovich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding cancelation support

Long running operations are typically performed on a different thread, which keeps the UI responsive, but that may not be enough. Applications may want to provide a way to cancel a long-running operation. Prior to .NET 4, developers used various ways to orchestrate cancelations. Starting from .NET 4 there is a standard way to convey cancelation requests.

In this recipe, we'll see how to use this cancelation mechanism.

Getting ready

Open the CH11.AsyncCalc project. We'll enhance it with cancelation support.

How to do it...

We'll add the option to cancel the prime calculation operation.

  1. Open MainWindow.xaml. Add another button to the second StackPanel with the following markup:
    <Button Content="Cancel" Padding="4" Margin="10,0,0,0" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required