Using Collection Activities
This topic applies to Windows Workflow Foundation 4 (WF4).
This sample demonstrates how to use the collection activities (AddToCollection, ClearCollection, ExistsInCollection, and RemoveFromCollection) with a class that implements the ICollection interface and how to create a custom activity that iterates over a collection to print out the contents of each element in the collection. The custom activity, which is named PrintCollection
, prints to the console the item members of a collection named Numbers
.
The following table describes the four activities that provide collection manipulation for workflows.
Activity name | Description |
---|---|
Adds an item to a collection. |
|
Clears all items in a collection |
|
Returns true if specified item exists in collection. |
|
Removes an item from a collection. |
The sample consists of two solutions, one under the CodedWorkflow directory and the other under the DesignerWorkflow directory. They demonstrate two different ways of using the activities for the same purposes.
Solution |
Description |
Main Files |
CodedWorkflow |
Sample client application that demonstrates how to invoke the collection activities programmatically. |
PrintCollection.cs: helper activity to print out to the console every item in a collection. Program.cs: programmatically builds a sequence activity that contains a series of collection activities, and executes it. |
DesignerWorkflow |
Sample client application that demonstrates how to use the collection activities declaratively in the workflow designer. |
CollectionWorkflow.xaml: a workflow created declaratively with the designer that uses the collection activities. PrintCollection.cs: helper activity to print out to the console every item in a collection. Program.cs: invokes the workflow described in CollectionWorkflow.xaml. |
In the demonstration, the item members of collection Numbers
are printed on the console using a custom-defined activity called PrintCollection
.
To use this sample
Using Visual Studio 2010, open the Collection.sln solution file.
To build the solution, press CTRL+SHIFT+B.
To run the solution, press CTRL+F5.
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\Built-InActivities\Collection
|