This sample demonstrates how to author a workflow that synchronizes the execution of groups of activities. This is useful, for example, to synchronize access to a shared resource.
In this sample, the workflow has a ParallelActivity that contains two branches. Each branch contains a SynchronizationScopeActivity activity. Two CodeActivity activities in each branch try to increment and decrement a workflow instance count. One code branch increments (count++) while the other code branch decrements (count--).
The two SynchronizedScope instances will be synchronized because they share a common value in their SynchronizationHandles property, "syncMutex".This ensures that after the first SynchronizedScope activity begins executing it will be allowed to complete before the other SynchronizedScope can begin. While this will not change the final value of the "count" field in this simple example, it does impact the intermediate values. To see the behavior without synchronization, change the value of the SynchronizationHandles property on one of the SynchronizedScopes, so that the two SynchronizedScopes are no longer synchronized.
When you build and run the sample, your output will appear similar to the following:
To build the sample
Download the sample by clicking Download Sample in this topic.
This extracts the sample project to your local hard disk.
Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.
Go to the source directory of the sample.
At the command prompt, type MSBUILD <Solution file name>.
To run the sample
- In the SDK Command Prompt window, run the .exe file in the Synchronized\bin\debug folder (or the Synchronized\bin folder for the Visual Basic version of the sample), which is located below the main folder for the sample.
Using the ParallelActivity Activity
Using the ReplicatorActivity Activity
Using the ConditionedActivityGroup Activity
Using the SynchronizationScopeActivity Activity
Windows Workflow Foundation Samples
© 2007 Microsoft Corporation. All rights reserved.