Export (0) Print
Expand All

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

Invokes the activity passed to the WorkflowInvoker(Activity) constructor synchronously with the specified IDictionary<TKey, TValue> of input parameters and the specified time-out interval.

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

public IDictionary<string, Object> Invoke(
	IDictionary<string, Object> inputs,
	TimeSpan timeout
)

Parameters

inputs
Type: System.Collections.Generic.IDictionary<String, Object>
The dictionary of input parameters to 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: System.Collections.Generic.IDictionary<String, Object>
A dictionary of the root activity’s OutArgument and InOutArgument values keyed by argument name that represent the outputs 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.

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 that contains two WriteLine activities and a Delay activity configured with a Duration of one minute. This workflow is invoked twice; the first time with a time-out interval of two minutes, and the second time with a time-out interval of 30 seconds. The first workflow completes successfully, but the second one does not and a TimeoutException is thrown and the following message is displayed.

The operation did not complete within the allotted timeout of 00:00:30. The time allotted to this operation may have been a portion of a longer timeout.

Activity wf = new Sequence()
{
    Activities = 
    {
        new WriteLine()
        {
            Text = "Before the 1 minute delay."
        },
        new Delay()
        {
            Duration = TimeSpan.FromMinutes(1)
        },
        new WriteLine()
        {
            Text = "After the 1 minute delay."
        }
    }
};

WorkflowInvoker invoker = new WorkflowInvoker(wf);

// This workflow completes successfully.
invoker.Invoke(TimeSpan.FromMinutes(2));

// This workflow does not complete and a TimeoutException
// is thrown.
try
{
    invoker.Invoke(TimeSpan.FromSeconds(30));
}
catch (TimeoutException ex)
{
    Console.WriteLine(ex.Message);
}


For an example of using Invoke with input and output arguments, see the overload of Invoke() with the same parameters as this overload without the time-out interval.

.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