This documentation is archived and is not being maintained.

For Activity

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

The For sample demonstrates how to build a custom activity that inherits from NativeActivity, and use it in a workflow to execute a real world example. The custom activity included in this sample functions like the C# for statement. T

The For custom activity has properties named InitAction, IterationAction, Condition, and Body that correspond to the initialization statement, iterative statement, continuation condition, and body statement respectively found in the standard C# For statement.

The following table describes the key files in the sample.

File Description

For.cs

Class definition for the For custom activity, which extends the NativeActivity class to provide the functionality of the C# For statement.

Program.cs

A client application that performs basic iterative work on a collection using the custom For activity.

Dd758796.note(en-us,VS.100).gifNote:
When using the For custom activity, ensure that the Condition property is set; otherwise an infinite loop could occur.

Demonstrates

Create a custom activity that inherits from NativeActivity.

Discussion

The following table describes the properties of the activity included in this sample.

InitAction
Initialization statement

IterationAction
Iterative statement

Condition
Continuation statement

Body
Body statement

The activity inherits from NativeActivity to gain access to runtime features such as scheduling additional activities to run, using one of the ScheduleActivity methods of NativeActivityContext.

To use this sample

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

  2. Build the solution, by pressing CTRL+SHIFT+B.

  3. Run the solution, by pressing F5.

Dd758796.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\Scenario\ActivityLibrary\For

Show: