Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Synchronized Sample 

Download sample

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.

Synchronized data access is an important consideration for composite activities such as ParallelActivity, ReplicatorActivity, and ConditionedActivityGroup that have parallel execution paths.

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 since they share a common value in their SynchronizationHandles property, "syncMutex".This ensures that once 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

  1. Download the sample by clicking Download Sample in this topic.

    This extracts the sample project to your local hard disk.

  2. Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.

  3. Go to the source directory of the sample.

  4. 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 VB version of the sample), which is located below the main folder for the sample.

See Also

Footer image
Send comments about this topic to Microsoft.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.