This sample demonstrates how to use the CancellationScope activity to cancel work in an application.
Many middle tier components and services rely on the well-known programming construct of transactions to handle cancellation for them. However, there are many situations in which work that cannot be done in a transaction must be canceled. Using cancellation is more difficult than using transactions, because work that must be canceled must first be tracked. .NET Framework 4 helps you with this by providing a CancellationScope activity.
Cancellation can be triggered either from within an activity or from the activity's parent. Child activities are scheduled by their parent activity (such as a Sequence, Parallel, Flowchart, or a custom composite activity). The parent activity can cancel child activities for any reason. For example, a Parallel activity with three child branches will cancel the remaining child branches whenever it completes a branch and the CompletionCondition expression evaluates to true. The workflow can also be canceled externally by the host application by calling Cancel.
This sample demonstrates cancelling an activity from within the activity itself.
The scenario that the sample uses to demonstrate the CancellationScope activity is a client wanting to buy a ticket to Miami as soon as possible. There are two travel agencies that want the business. The sample uses two CancellationScope within a Parallel activity to model this business logic. The CompletionCondition of the Parallel activity is set to true; since the CompletionCondition is checked after any branch completes, this will cause the remaining branch to be canceled after the first branch completes. The client application asks both agencies to buy the ticket, and when the first one confirms that the ticket has been bought, the application cancels the order at the other agency.
To use this sample
Using Visual Studio 2010, open the CancelationScopeXAML.sln solution file.
To build the solution, press CTRL+SHIFT+B.
To run the solution, press CTRL+F5.
The samples may already be installed on your machine. Check for the following (default) directory before continuing.