Delen via


Creating Custom Activities

To create a basic custom activity, you inherit from the Activity class or a derived type. To create a custom composite activity, you inherit from the CompositeActivity class or a derived type.

Note

Creating a custom activity that inherits from a custom activity that contains child activities is not supported.

The custom activity class you create defines the properties, events, and execution logic for the custom activity.

Properties

You may use two types of activity properties in your custom activity: meta properties and instance properties. A meta property is immutable at run time, so the property must be set to a literal value at design time. An instance property can be set at design time or the property can be bound to instance data, in which case the actual value is not determined until run time. Instance properties can also be modified directly during workflow execution.

For more information about activity properties, see Using Activity Properties.

Execution Logic

When you create a custom activity, you must explicitly handle the execution logic of your activity through the Execute method. Additional Activity methods may be overridden as required in your activity.

Attributes

Your custom activity can be decorated with various attributes to indicate such things as which activity designer should be loaded, what validator should be used when validating your activity, and so on. The following table lists all the attributes that you can use to decorate your custom activity.

Attribute Description

ActivityCodeGeneratorAttribute

Indicates which ActivityCodeGenerator-derived class will be used to generate compile-time code for your custom activity.

ActivityValidatorAttribute

Indicates which ActivityValidator-derived class will be used to validate your custom activity.

AlternateFlowActivityAttribute

Indicates that the activity supports an alternative flow.

ContentPropertyAttribute

Indicates that the property name of a particular property in your custom activity will not be serialized.

DefaultEventAttribute

Indicates the default event of your custom activity.

DesignerAttribute

Indicates which ActivityDesigner-derived class will be used to implement design-time services for your custom activity.

DesignerCategoryAttribute

Indicates that the designer for your custom activity belongs to a certain category.

DesignerSerializerAttribute

Indicates which serializer (ActivityMarkupSerializer, ActivityCodeDomSerializer, ActivityTypeCodeDomSerializer, CompositeActivityMarkupSerializer, or a derivative of any one of them) will be used to serialize your custom activity.

PersistOnCloseAttribute

Indicates that the current workflow instance must be persisted when the adorned activity completes its execution.

RuntimeNamePropertyAttribute

Indicates the run-time name for your custom activity.

ToolboxBitmapAttribute

Indicates the icon to use to represent your custom activity in a container, such as a custom workflow designer.

ToolboxItemAttribute

Indicates which ActivityToolboxItem-derived class will be used with your custom activity in a container, such as a custom workflow designer.

ToolboxItemFilterAttribute

Indicates the filter string and filter type to use for your custom activity when it is used in a container, such as a custom workflow designer.

Warning

If your custom activity uses the PersistOnCloseAttribute, the workflow that uses your custom activity must specify a persistence service to use or an exception is thrown when the workflow is started.

Attributes can be "overridden" in the sense that if you decorate your custom activity with attributes used by your base activity, your overridden values are used against your custom activity. For example, you may want to create your own toolbox bitmap for your custom activity, but still use the default serializer and activity validator of your base activity. To do this, you would only have to decorate your custom activity with the ToolboxItemAttribute and set the value accordingly.

Creating Custom Activities from Default Windows Workflow Foundation Activities

You can derive your custom activity from the following activity types:

Activity Type Description

Activity

Base type that all activities derive from.

CallExternalMethodActivity

Calls methods on a host during local communication.

CompositeActivity

All composite activities derive from this type.

HandleExternalEventActivity

Handles incoming events raised by a host during local communication.

SequenceActivity

Used to create custom composite activities that have child activities executing in sequence.

SequentialWorkflowActivity

Used to create sequential workflows.

StateActivity

Used in state machine workflows to handle events or initialization for a given state.

StateMachineWorkflowActivity

Used to create state machine workflows.

Customizing Activities

You have the option of customizing the default logic of a custom activity by using a set of related classes that encapsulate specific pieces of functionality.

The following sections provide more detail on these areas:

Creating Custom Composite Activities

Serializing Custom Activities

How to Generate Code Using Custom Activities

See Also

Reference

Activity
CompositeActivity
ActivityBind

Concepts

Using Activity Properties
Activity Validation Logic Overview
Creating a Custom Activity Designer

Other Resources

Developing Windows Workflow Foundation Activities