Share via


InvokeMethod Activity Designer

InvokeMethod designer is used to create and configure an InvokeMethod activity.

The InvokeMethod Activity

The InvokeMethod calls a public method of a specified object or type.

Using the InvokeMethod Activity Designer

The InvokeMethod activity designer can be found in the Primitives category of the Toolbox, which is accessed by clicking the Toolbox tab Workflow Designer (Alternatively, select Toolbar from the View menu, or CRTL+ALT+X.)

The InvokeMethod activity designer can be dragged from the Toolbox and dropped on to the Workflow Designer surface where ever activities are usually placed, such as inside a Sequence. This creates an InvokeMethod activity with a default DisplayName of InvokeMethod. The DisplayName can be edited in the header of the InvokeMethod activity designer or in the DisplayName box of the property grid.

The InvokeMethod Properties

The following table shows the InvokeMethod properties and describes how they are used in the designer. These properties can be edited in property grid and some can be edited on Workflow Designerdesigner surface.

Property Name Required Usage

DisplayName

False

The friendly name of the InvokeMethod activity. The default value is InvokeMethod.

Although the DisplayName is not strictly required, it is a best practice to use one.

MethodName

True

The name of the method to be called when the activity executes. The called method must be declared as public. This property can be edited on designer surface. This is a mandatory property.

Parameters

False

The parameter collection of the called method. The parameters must be added to the collection in the same order that they appear in the method signature. In the property grid, click the ellipses button in the Parameters field, it displays the Parameters dialog to let you set this property. Click the Create Argument button to add the parameters.

Result

False

The return value of the method call.

RunAsynchronously

True

Specifies whether the method is called asynchronously. The default value is False.

TargetObject

False

The object that contains the method to call. This property can be edited on designer surface.

Either the TargetObject or the TargetType is required to be set.

TargetType

False

The type of TargetObject. This property can be edited on the designer surface. This property must only be set if the method called is static.

To pass parameters as a C# out parameter (for example, Method1(out myParam)), you should use OutArgument instead of InOutArgument

Methods with arguments called TargetObject or Result cannot be invoked using the InvokeMethod activity. The reason for this is that InvokeMethod activity registers the GenericTypeArguments, TargetObject and Result in CacheMetadata.

The algorithm for registering the parameters in CacheMetadata is shown in the following list:

  1. Register TargetObject argument.

  2. Register Result argument.

  3. Iterate through the Parameters collection and register each argument.

The resulting exception is of type InvalidWorkflowException with the following message: 'InvokeMethod': A variable, RuntimeArgument or a DelegateArgument already exists with the name 'TargetObject'. Names must be unique within an environment scope.

This restriction does not apply to TargetType and RunAsynchronously because they are not workflow arguments and therefore are not registered in the GenericTypeArguments collection of InvokeMethod activity in CacheMetadata method.

See Also

Concepts

Assign Activity Designer
Delay Activity Designer
WriteLine Activity Designer

Other Resources

Primitives Activity Designers