Using AsyncOperationContext in an Activity Sample

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

This sample demonstrates how to develop a custom CodeActivity that uses AsyncOperationContext to perform work asynchronously outside of the workflow.

Sample Details

The sample activity uses the BeginWrite and EndWrite methods on the FileStream class to asynchronously write data to a file. The pattern introduced here can be adapted for use with other asynchronous methods. While the asynchronous operation is executing, other activities in the workflow can execute, but the workflow cannot be persisted.

To set up, build, and run the sample

  1. Open the Async.sln sample solution in Visual Studio 2010.

  2. Build and run the solution.

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

<InstallDrive>:\WF_WCF_Samples

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.

<InstallDrive>:\WF_WCF_Samples\WF\Basic\CustomActivities\Code-Bodied\Async