Export (0) Print
Expand All

Activity Class

Represents the fundamental building block of workflows. Activity is the base class for all activities.

Namespace:  System.Workflow.ComponentModel
Assembly:  System.Workflow.ComponentModel (in System.Workflow.ComponentModel.dll)

[RuntimeNamePropertyAttribute("Name")]
[ActivityCodeGeneratorAttribute(typeof(ActivityCodeGenerator))]
[ActivityValidatorAttribute(typeof(ActivityValidator))]
[ToolboxBitmapAttribute(typeof(Activity), "Design.Resources.Activity.png")]
public class Activity : DependencyObject

An Activity is the fundamental building block of workflows. An Activity defines a set of properties and events, such as any class, along with execution logic that defines the activity's run-time behavior. A set of additional components can be associated with an Activity. These include, but are not limited to a validator, a code generator, custom serializers, and a designer.

All activities share a common set of properties defined on the Activity base class. Each Activity can declare its own additional properties according to its requirements by extending this class. Because Activity derives from DependencyObject, properties can be defined as standard CLR properties and as dependency properties.

The execution logic of an Activity fulfills a contract that exists between any Activity and the workflow runtime. You must document the execution logic of any Activity in a functional sense, so that a workflow developer who uses the Activity knows how it behaves. The execution logic itself is hidden from the workflow developer who includes the activity in a workflow, because the execution logic is part of a contract that exists strictly between the workflow runtime and the Activity.

This example defines an activity whose purpose is to send an email. The activity defines one property, Subject, that uses a dependency property in its implementation. Other properties can be defined in a similar way. The Execute method is overridden to provide the logic for sending the email. For a complete example, see the Send E-mail Activity Sample.

public class SendEmail : Activity
{
    public static readonly DependencyProperty SubjectProperty =
        DependencyProperty.Register("Subject", typeof(string), typeof(SendEmail));

    public string Subject
    {
        get { return base.GetValue(SubjectProperty) as string; }
        set { base.SetValue(SubjectProperty, value); }
    }

    // Define other properties...

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        // Logic to send the e-mail goes here...
        return ActivityExecutionStatus.Closed;
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2014 Microsoft