This documentation is archived and is not being maintained.

Auto-Confirm Pattern

This topic applies to Windows Workflow Foundation 4 (WF4).

This sample consists of three scenarios that run illustrating a custom AutoConfirmScope activity. The first sample shows the successful execution of a sequence of four compensable activities where the second and third are nested in an AutoConfirmScope. The second sample shows the same sequence with an exception occurring after the execution of the fourth CompensableActivity. The third scenario shows the same sequence with an exception occurring in the AutoConfirmScope after the second CompensableActivity completes.

The sample demonstrates the auto-confirm pattern where all child compensable activities are confirmed upon successful completion of the scope. This pattern defines the lifetime of all child compensable activities, as they can no longer be compensated or confirmed.

The scope consists of a TryCatch where the Try is an internal CompensableActivity. The user-specified body of the AutoConfirmScope is the body of the inner CompensableActivity. When this internal CompensableActivity completes, it produces a CompensationToken as an out-argument. The AutoConfirmScope uses a Finally to check whether the token has been produced and if it has then it confirms the inner CompensableActivity. The inner CompensableActivity invokes the default compensation for any compensable activities that may exist in its body.

The first scenario shows successful execution of the workflow and demonstrates that the second and third compensable activities are already confirmed when the workflow completes and the first and fourth are confirmed. This produces a confirmation order of three, two, four, and one.

The second scenario shows an exception after the four compensable activities have completed. Because compensable activities two and three are already confirmed they are unaffected but one and four are compensated. This produces confirm three, confirm two, compensate four and compensate one.

The final scenario shows unsuccessful execution of the AutoConfirmScope. In this scenario, an exception occurs after the completion of the second CompensableActivity. Because the third and fourth compensable activities have not executed, they are unaffected. Because the scope did not complete successfully, the second CompensableActivity does not get confirmed. This produces and compensation order of two then one.

To use this sample

  1. Using Visual Studio 2010, open the AutoConfirmSample.sln solution file.

  2. To build the solution, press CTRL+SHIFT+B.

  3. To run the solution, press CTRL+F5.

Dd744849.Important(en-us,VS.100).gif Note:
The samples may already be installed on your machine. Check for the following (default) directory before continuing.


If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.