WorkflowInvoker.Invoke<TResult> Method (Activity<TResult>, IDictionary<String, Object>, IDictionary<String, Object>, TimeSpan)

.NET Framework (current version)
 

Invokes a workflow synchronously using the specified workflow definition, IDictionary<TKey, TValue> of input parameters, IDictionary<TKey, TValue> of additional output parameters, and time-out interval.

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

public static TResult Invoke<TResult>(
	Activity<TResult> workflow,
	IDictionary<string, object> inputs,
	out IDictionary<string, object> additionalOutputs,
	TimeSpan timeout
)

Parameters

workflow
Type: System.Activities.Activity<TResult>

The workflow definition of the workflow to invoke.

inputs
Type: System.Collections.Generic.IDictionary<String, Object>

The dictionary of input parameters to the workflow, keyed by argument name.

additionalOutputs
Type: System.Collections.Generic.IDictionary<String, Object>

The dictionary of additional output parameters of the workflow, keyed by argument name.

timeout
Type: System.TimeSpan

The interval in which the workflow must complete before it is aborted and a TimeoutException is thrown.

Return Value

Type: TResult

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

Type Parameters

TResult

The type of the workflow.

This method blocks until the workflow has completed, including idle time. All workflow execution is guaranteed to execute on the invoking thread. If the workflow does not complete within the specified time-out interval the workflow is aborted and a TimeoutException is thrown.

System_CAPS_noteNote

The TimeoutException is only thrown if the time-out interval elapses and the workflow becomes idle during execution. A workflow that takes longer than the specified time-out interval to complete, completes successfully if the workflow does not become idle.

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
Available since 4.0
Return to top
Show: