Export (0) Print
Expand All

WorkflowInvoker.Invoke Method (Activity, TimeSpan)

Invokes a workflow synchronously using the specified workflow definition and time-out interval.

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

public static IDictionary<string, Object> Invoke(
	Activity workflow,
	TimeSpan timeout
)

Parameters

workflow
Type: System.Activities.Activity

The workflow definition of the workflow to invoke.

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.

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."
        }
    }
};

// This workflow completes successfully.
WorkflowInvoker.Invoke(wf, TimeSpan.FromMinutes(2));

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

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

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft