Task 3: Create the Custom Activity Sequential Workflow
In this task, you create a basic sequential workflow that does not contain any activities. You will build upon this workflow as the tutorial progresses by adding the necessary activities and logic to communicate back to the host application.
Note |
---|
Although you are encouraged to follow the exercises in a linear manner, it is not required. You can start this exercise by opening the sample project and proceeding to the steps in the following section. |
Creating the Source File
Follow these steps to create the source file for a basic sequential workflow.
To create a sequential workflow source file
In your projects directory, create a new file named WebTearWorkflow.
Give it a .cs extension if you are creating a C# application, or a .vb extension for a Visual Basic application.
In the ItemGroup element that you added in Task 2: Create the Custom Activity Host Application, add a new Compile element.
Add a new attribute to the Compile element named Include.
Use the file name that you created in step 1 as the attribute value.
Add a new child element to the Compile element named SubType.
Give this element the value Component. Your ItemGroup node will appear as follows:
<ItemGroup> <Compile Include="CustomActivityHost.vb"> <SubType>Form</SubType> </Compile> <Compile Include="WebTearWorkflow.vb"> <SubType>Component</SubType> </Compile> </ItemGroup>
<ItemGroup> <Compile Include="CustomActivityHost.cs"> <SubType>Form</SubType> </Compile> <Compile Include="WebTearWorkflow.cs"> <SubType>Component</SubType> </Compile> </ItemGroup>
Defining the Workflow
To define the sequential workflow
In the WebTearWorkflow file, add the following namespace directives to import the types that you need for the workflow.
Imports System Imports System.Workflow.ComponentModel Imports System.Workflow.Activities
using System; using System.Workflow.Activities; using System.Workflow.ComponentModel;
Create a new sealed class named WebTearWorkflow in the Microsoft.Samples.Workflow.Tutorials.CustomActivity namespace.
Derive the class created in the previous step from SequentialWorkflowActivity.
Namespace Microsoft.Samples.Workflow.Tutorials.CustomActivity Public NotInheritable Partial Class WebTearWorkflow : Inherits SequentialWorkflowActivity End Class End Namespace
namespace Microsoft.Samples.Workflow.Tutorials.CustomActivity { public sealed partial class WebTearWorkflow : SequentialWorkflowActivity { } }
Create a default constructor in the WebTearWorkflow class.
In the constructor, call the InitializeComponent method that you create in the next step.
Public Sub New() InitializeComponent() End Sub
public WebTearWorkflow() { InitializeComponent(); }
Create a private method named InitializeComponent in the WebTearWorkflow class.
In the InitializeComponent method, set the following properties:
Set the CanModifyActivities property of the workflow to true.
Set the Name property to the value "WebTearWorkflow".
Set the CanModifyActivities property to false.
Private Sub InitializeComponent() Me.CanModifyActivities = True Me.Name = "WebTearWorkflow" Me.CanModifyActivities = False End Sub
private void InitializeComponent() { this.CanModifyActivities = true; this.Name = "WebTearWorkflow"; this.CanModifyActivities = false; }
Compiling the Code
Click Start, point to Programs, point to Microsoft .NET Framework SDK v2.0, and then click SDK Command Prompt.
Go to the source directory of the tutorial.
At the command prompt, type MSBUILD to build the project.
In Exercise 2: Create the Custom Activity and Workflow, you will create the custom activity and add it to the workflow that you created in this task.
See Also
Reference
SequentialWorkflowActivity
CanModifyActivities
Other Resources
Exercise 2: Create the Custom Activity and Workflow
Tutorial: Create a Sequential Workflow
Simple Sequential Workflow
Send comments about this topic to Microsoft.