Task 3: Create the Custom Activity Sequential Workflow 

Download sample

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.

NoteNote

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

  1. 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.

  2. In the ItemGroup element that you added in Task 2: Create the Custom Activity Host Application, add a new Compile element.

  3. Add a new attribute to the Compile element named Include.

    Use the file name that you created in step 1 as the attribute value.

  4. 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

  1. 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;
    
  2. Create a new sealed class named WebTearWorkflow in the Microsoft.Samples.Workflow.Tutorials.CustomActivity namespace.

  3. 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
        {
        }
    }
    
  4. 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();
    }
    
  5. Create a private method named InitializeComponent in the WebTearWorkflow class.

  6. 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

  1. Click Start, point to Programs, point to Microsoft .NET Framework SDK v2.0, and then click SDK Command Prompt.

  2. Go to the source directory of the tutorial.

  3. 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

Footer image

Send comments about this topic to Microsoft.