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.
CH11.AsyncCalc project. We'll enhance it with cancelation support.
We'll add the option to cancel the prime calculation operation.
MainWindow.xaml. Add another button to the second
StackPanelwith the following markup:
<Button Content="Cancel" Padding="4" Margin="10,0,0,0" ...