WorkflowInvoker.Invoke Method (TimeSpan)

.NET Framework (current version)
 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Invokes a workflow synchronously with the specified time-out interval.

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

public IDictionary<string, object> Invoke(
	TimeSpan timeout
)

Parameters

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.

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 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 output arguments, see the overload of Invoke with the same parameters as this overload without the time-out interval.

.NET Framework
Available since 4.0
Return to top
Show: