Compartilhar via


Task 2: Use the Custom Activity in a Sequential Workflow

Download sample

In this task, you add the WebTear custom activity that you created in Task 1: Create the Custom Activity to your WebTearWorkflow sequential workflow.

This workflow uses a string property that is set by the host application for the URL value and binds it to the UrlProperty defined in the WebTear custom activity. When the WebTear activity is run in the workflow, the activity downloads the text from the requested URL and raises an event. The workflow in this task creates an event handler for this event to retrieve the data downloaded by the activity.

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.

To create the sequential workflow

  1. In the WebTearWorkflow class, create a private String field named pageUrl and a private String field named pageData.

    private string pageUrl;
    private string pageData;
    
  2. Double-click WebTearWorkflow to open it in the designer. Select View, Toolbox from the Visual Studio main menu to open the toolbox. Drag a WebTearActivity component from the WebTearWorkflow Components section onto the workflow surface between the start and end icons in the designer.

  3. In the WebTearWorkflow class, create a public String property named Url.

    Create a get method that returns the value of the pageUrl field and a set method that sets the value of the pageUrl field.

    public string Url
    {
        get { return pageUrl; }
        set { pageUrl = value; }
    }
    
  4. In the WebTearWorkflow class, create a public String property named Data.

    Create a get method that returns the value of the pageData field and a set method that sets the value of the pageData field.

    public string Data
    {
        get { return pageData; }
        set { pageData = value; }
    }
    
  5. Select the new activity and in the Properties window, select the button next to the Url field. This opens the Bind ‘Url’ to an activity’s property window.

  6. Select Url from the list of existing members.

  7. In the Properties window for the new activity, enter webTearActivity1_PageFinished for the PageFinished property. This creates an event handler for the event in the WebTearWorkflow class.

  8. In the webTearActivity_PageFinished method, set the pageData field of the workflow equal to the Data property that is defined in the PageFinishedEventArgs parameter.

    private void webTearActivity_PageFinished(object sender, PageFinishedEventArgs e)
    {
        this.pageData = e.Data;
    }
    

Compiling the Code

For more information about compiling your code, see Compiling the Code.

In Task 3: Modify the Custom Activity Host Application, you enable the host application to start the workflow when a button is clicked.

See Also

Other Resources

Task 3: Modify the Custom Activity Host Application
Tutorial: Create a Custom WF Activity
Custom Activities

Copyright © 2007 by Microsoft Corporation. All rights reserved.
Last Published: 2010-03-04