Export (0) Print
Expand All

WorkflowInvoker.Invoke(Of TResult) Method (Activity(Of TResult))

Invokes a workflow synchronously using the workflow definition passed to the WorkflowInvoker(Activity) constructor.

Namespace:  System.Activities
Assembly:  System.Activities (in System.Activities.dll)

'Declaration
Public Shared Function Invoke(Of TResult) ( _
	workflow As Activity(Of TResult) _
) As TResult

Type Parameters

TResult

The type of the workflow.

Parameters

workflow
Type: System.Activities.Activity(Of TResult)
The workflow definition of the workflow to invoke. The workflow definition needs to derive from ActivityWithResult.

Return Value

Type: TResult
A value of type TResult with the result of the execution of the activity.

This method blocks until the workflow has completed, including idle time. All workflow execution is guaranteed to execute on the invoking thread. To configure a time-out interval in which the workflow must complete, use one of the Invoke overloads that take a TimeSpan.

The following example invokes a workflow consisting of a single Add activity that has two input arguments and since it derives from CodeActivity<int> it has one well-defined Result output argument. When the workflow is invoked, the arguments dictionary is passed which contains the values for each input argument, keyed by argument name. When the call to Invoke returns, the value of the Result output argument is returned. This code example is based off of the Using the WorkflowInvoker Class sample.


public sealed class Add : CodeActivity<int>
{
    public InArgument<int> X { get; set; }
    public InArgument<int> Y { get; set; }

    protected override int Execute(CodeActivityContext context)
    {
        int x = X.Get(context);
        int y = Y.Get(context);

        return x + y;
    }
}



int x = 1;
int y = 2;

Dictionary<string, object> arguments = new Dictionary<string, object>();
arguments.Add("X", x);
arguments.Add("Y", y);

Console.WriteLine("Invoking Add.");

int result = WorkflowInvoker.Invoke(new Add(), arguments);

Console.WriteLine("{0} + {1} = {2}", x, y, result);


.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft