Redigera

Dela via


WorkflowInvoker.Invoke Method

Definition

Invokes a workflow synchronously and returns a dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Overloads

Invoke(Activity, IDictionary<String,Object>, TimeSpan)

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

Invoke(Activity, TimeSpan)

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

Invoke(Activity, IDictionary<String,Object>)

Invokes a workflow synchronously using the specified workflow definition and IDictionary<TKey,TValue> of input parameters.

Invoke(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.

Invoke(IDictionary<String,Object>)

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

Invoke(Activity)

Invokes a workflow synchronously using the specified workflow definition.

Invoke()

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

Invoke(TimeSpan)

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

Invoke<TResult>(Activity<TResult>)

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

Invoke<TResult>(Activity<TResult>, IDictionary<String,Object>)

Invokes a workflow synchronously using the specified workflow definition and IDictionary<TKey,TValue> of input parameters.

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

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

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

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.

Remarks

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.

Invoke(Activity, IDictionary<String,Object>, TimeSpan)

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

public:
 static System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Invoke(System::Activities::Activity ^ workflow, System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs, TimeSpan timeout);
public static System.Collections.Generic.IDictionary<string,object> Invoke (System.Activities.Activity workflow, System.Collections.Generic.IDictionary<string,object> inputs, TimeSpan timeout);
static member Invoke : System.Activities.Activity * System.Collections.Generic.IDictionary<string, obj> * TimeSpan -> System.Collections.Generic.IDictionary<string, obj>
Public Shared Function Invoke (workflow As Activity, inputs As IDictionary(Of String, Object), timeout As TimeSpan) As IDictionary(Of String, Object)

Parameters

workflow
Activity

The workflow definition of the workflow to invoke.

inputs
IDictionary<String,Object>

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

timeout
TimeSpan

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

Returns

A dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Examples

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

Remarks

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.

Note

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.

Applies to

Invoke(Activity, TimeSpan)

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

public:
 static System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Invoke(System::Activities::Activity ^ workflow, TimeSpan timeout);
public static System.Collections.Generic.IDictionary<string,object> Invoke (System.Activities.Activity workflow, TimeSpan timeout);
static member Invoke : System.Activities.Activity * TimeSpan -> System.Collections.Generic.IDictionary<string, obj>
Public Shared Function Invoke (workflow As Activity, timeout As TimeSpan) As IDictionary(Of String, Object)

Parameters

workflow
Activity

The workflow definition of the workflow to invoke.

timeout
TimeSpan

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

Returns

A dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Examples

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.

Remarks

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.

Note

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.

Applies to

Invoke(Activity, IDictionary<String,Object>)

Invokes a workflow synchronously using the specified workflow definition and IDictionary<TKey,TValue> of input parameters.

public:
 static System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Invoke(System::Activities::Activity ^ workflow, System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs);
public static System.Collections.Generic.IDictionary<string,object> Invoke (System.Activities.Activity workflow, System.Collections.Generic.IDictionary<string,object> inputs);
static member Invoke : System.Activities.Activity * System.Collections.Generic.IDictionary<string, obj> -> System.Collections.Generic.IDictionary<string, obj>
Public Shared Function Invoke (workflow As Activity, inputs As IDictionary(Of String, Object)) As IDictionary(Of String, Object)

Parameters

workflow
Activity

The workflow definition of the workflow to invoke.

inputs
IDictionary<String,Object>

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

Returns

A dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Examples

The following example invokes a workflow consisting of a single Divide activity that has two input arguments and two output arguments. 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, each output argument is returned in the outputs dictionary, also keyed by argument name.

public sealed class Divide : CodeActivity
{
    [RequiredArgument]
    public InArgument<int> Dividend { get; set; }

    [RequiredArgument]
    public InArgument<int> Divisor { get; set; }

    public OutArgument<int> Remainder { get; set; }
    public OutArgument<int> Result { get; set; }

    protected override void Execute(CodeActivityContext context)
    {
        int quotient = Dividend.Get(context) / Divisor.Get(context);
        int remainder = Dividend.Get(context) % Divisor.Get(context);

        Result.Set(context, quotient);
        Remainder.Set(context, remainder);
    }
}
int dividend = 500;
int divisor = 36;

Dictionary<string, object> arguments = new Dictionary<string, object>();
arguments.Add("Dividend", dividend);
arguments.Add("Divisor", divisor);

IDictionary<string, object> outputs =
    WorkflowInvoker.Invoke(new Divide(), arguments);

Console.WriteLine("{0} / {1} = {2} Remainder {3}",
    dividend, divisor, outputs["Result"], outputs["Remainder"]);

If the workflow derives from ActivityWithResult, such as CodeActivity<TResult> or Activity<TResult>, and there are output arguments in addition to the well-defined Result output argument, a non-generic overload of Invoke, such as this one, must be used in order to retrieve the additional arguments. To do this, the workflow definition passed into Invoke must be of type Activity. In this example the Divide activity derives from CodeActivity<int>, but is declared as Activity so that this overload of Invoke, which returns a dictionary of arguments instead of a single return value, is used.

public sealed class Divide : CodeActivity<int>
{
    public InArgument<int> Dividend { get; set; }
    public InArgument<int> Divisor { get; set; }
    public OutArgument<int> Remainder { get; set; }

    protected override int Execute(CodeActivityContext context)
    {
        int quotient = Dividend.Get(context) / Divisor.Get(context);
        int remainder = Dividend.Get(context) % Divisor.Get(context);

        Remainder.Set(context, remainder);

        return quotient;
    }
}
int dividend = 500;
int divisor = 36;

Dictionary<string, object> arguments = new Dictionary<string, object>();
arguments.Add("Dividend", dividend);
arguments.Add("Divisor", divisor);

Activity wf = new Divide();

IDictionary<string, object> outputs =
    WorkflowInvoker.Invoke(wf, arguments);

Console.WriteLine("{0} / {1} = {2} Remainder {3}",
    dividend, divisor, outputs["Result"], outputs["Remainder"]);

Remarks

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.

Applies to

Invoke(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.

public:
 System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Invoke(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs, TimeSpan timeout);
public System.Collections.Generic.IDictionary<string,object> Invoke (System.Collections.Generic.IDictionary<string,object> inputs, TimeSpan timeout);
member this.Invoke : System.Collections.Generic.IDictionary<string, obj> * TimeSpan -> System.Collections.Generic.IDictionary<string, obj>
Public Function Invoke (inputs As IDictionary(Of String, Object), timeout As TimeSpan) As IDictionary(Of String, Object)

Parameters

inputs
IDictionary<String,Object>

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

timeout
TimeSpan

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

Returns

A dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Examples

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.

Remarks

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.

Note

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.

Applies to

Invoke(IDictionary<String,Object>)

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

public:
 System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Invoke(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs);
public System.Collections.Generic.IDictionary<string,object> Invoke (System.Collections.Generic.IDictionary<string,object> inputs);
member this.Invoke : System.Collections.Generic.IDictionary<string, obj> -> System.Collections.Generic.IDictionary<string, obj>
Public Function Invoke (inputs As IDictionary(Of String, Object)) As IDictionary(Of String, Object)

Parameters

inputs
IDictionary<String,Object>

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

Returns

A dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Examples

The following example invokes a workflow consisting of a single Divide activity that has two input arguments and two output arguments. 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, each output argument is returned in the outputs dictionary, also keyed by argument name.

public sealed class Divide : CodeActivity
{
    [RequiredArgument]
    public InArgument<int> Dividend { get; set; }

    [RequiredArgument]
    public InArgument<int> Divisor { get; set; }

    public OutArgument<int> Remainder { get; set; }
    public OutArgument<int> Result { get; set; }

    protected override void Execute(CodeActivityContext context)
    {
        int quotient = Dividend.Get(context) / Divisor.Get(context);
        int remainder = Dividend.Get(context) % Divisor.Get(context);

        Result.Set(context, quotient);
        Remainder.Set(context, remainder);
    }
}
int dividend = 500;
int divisor = 36;

Dictionary<string, object> arguments = new Dictionary<string, object>();
arguments.Add("Dividend", dividend);
arguments.Add("Divisor", divisor);

WorkflowInvoker invoker = new WorkflowInvoker(new Divide());

IDictionary<string, object> outputs = invoker.Invoke(arguments);

Console.WriteLine("{0} / {1} = {2} Remainder {3}",
    dividend, divisor, outputs["Result"], outputs["Remainder"]);

If the workflow derives from ActivityWithResult, such as CodeActivity<TResult> or Activity<TResult>, and there are output arguments in addition to the well-defined Result output argument, a non-generic overload of Invoke, such as this one, must be used in order to retrieve the additional arguments. To do this, the workflow definition passed into the WorkflowInvoker constructor must be of type Activity. In this example the Divide activity derives from CodeActivity<int>, but is declared as Activity so that this overload of Invoke, which returns a dictionary of arguments instead of a single return value, is used.

public sealed class Divide : CodeActivity<int>
{
    public InArgument<int> Dividend { get; set; }
    public InArgument<int> Divisor { get; set; }
    public OutArgument<int> Remainder { get; set; }

    protected override int Execute(CodeActivityContext context)
    {
        int quotient = Dividend.Get(context) / Divisor.Get(context);
        int remainder = Dividend.Get(context) % Divisor.Get(context);

        Remainder.Set(context, remainder);

        return quotient;
    }
}
int dividend = 500;
int divisor = 36;

Dictionary<string, object> arguments = new Dictionary<string, object>();
arguments.Add("Dividend", dividend);
arguments.Add("Divisor", divisor);

Activity wf = new Divide();

WorkflowInvoker invoker = new WorkflowInvoker(wf);

IDictionary<string, object> outputs = invoker.Invoke(arguments);

Console.WriteLine("{0} / {1} = {2} Remainder {3}",
    dividend, divisor, outputs["Result"], outputs["Remainder"]);

Remarks

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.

Applies to

Invoke(Activity)

Invokes a workflow synchronously using the specified workflow definition.

public:
 static System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Invoke(System::Activities::Activity ^ workflow);
public static System.Collections.Generic.IDictionary<string,object> Invoke (System.Activities.Activity workflow);
static member Invoke : System.Activities.Activity -> System.Collections.Generic.IDictionary<string, obj>
Public Shared Function Invoke (workflow As Activity) As IDictionary(Of String, Object)

Parameters

workflow
Activity

The workflow definition of the workflow to invoke.

Returns

A dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Examples

The following example invokes a workflow consisting of a single DiceRoll activity. The DiceRoll activity has two output arguments that represent the results of the dice roll operation. When the call to Invoke returns, each output argument is returned in the outputs dictionary, keyed by argument name.

public sealed class DiceRoll : CodeActivity
{
    public OutArgument<int> D1 { get; set; }
    public OutArgument<int> D2 { get; set; }

    static Random r = new Random();

    protected override void Execute(CodeActivityContext context)
    {
        D1.Set(context, r.Next(1, 7));
        D2.Set(context, r.Next(1, 7));
    }
}
IDictionary<string, object> outputs =
    WorkflowInvoker.Invoke(new DiceRoll());

Console.WriteLine("The two dice are {0} and {1}.",
    outputs["D1"], outputs["D2"]);

If the workflow's root activity has no output arguments or they are not needed by the host, they can be disregarded. The following example invokes a workflow consisting of a single WriteLine activity that does not have any output arguments.

Activity wf = new WriteLine
{
    Text = "Hello World."
};

WorkflowInvoker.Invoke(wf);

Remarks

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.

Applies to

Invoke()

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

public:
 System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Invoke();
public System.Collections.Generic.IDictionary<string,object> Invoke ();
member this.Invoke : unit -> System.Collections.Generic.IDictionary<string, obj>
Public Function Invoke () As IDictionary(Of String, Object)

Returns

A dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Examples

The following example invokes a workflow consisting of a single DiceRoll activity. The DiceRoll activity has two output arguments that represent the results of the dice roll operation. When the call to Invoke returns, each output argument is returned in the outputs dictionary, keyed by argument name. The workflow is invoked twice, using the workflow definition passed into the WorkflowInvoker constructor.

public sealed class DiceRoll : CodeActivity
{
    public OutArgument<int> D1 { get; set; }
    public OutArgument<int> D2 { get; set; }

    static Random r = new Random();

    protected override void Execute(CodeActivityContext context)
    {
        D1.Set(context, r.Next(1, 7));
        D2.Set(context, r.Next(1, 7));
    }
}
WorkflowInvoker invoker = new WorkflowInvoker(new DiceRoll());

IDictionary<string, object> outputs =
    invoker.Invoke();

Console.WriteLine("The two dice are {0} and {1}.",
    outputs["D1"], outputs["D2"]);

outputs = invoker.Invoke();

Console.WriteLine("The next two dice are {0} and {1}.",
    outputs["D1"], outputs["D2"]);

If the workflow's root activity has no output arguments or they are not needed by the host, they can be disregarded. The following example invokes a workflow consisting of a single WriteLine activity that does not have any output arguments.

Activity wf = new WriteLine
{
    Text = "Hello World."
};

WorkflowInvoker invoker = new WorkflowInvoker(wf);

invoker.Invoke();

Remarks

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.

Applies to

Invoke(TimeSpan)

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

public:
 System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Invoke(TimeSpan timeout);
public System.Collections.Generic.IDictionary<string,object> Invoke (TimeSpan timeout);
member this.Invoke : TimeSpan -> System.Collections.Generic.IDictionary<string, obj>
Public Function Invoke (timeout As TimeSpan) As IDictionary(Of String, Object)

Parameters

timeout
TimeSpan

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

Returns

A dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Examples

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.

Remarks

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.

Note

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.

Applies to

Invoke<TResult>(Activity<TResult>)

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

public:
generic <typename TResult>
 static TResult Invoke(System::Activities::Activity<TResult> ^ workflow);
public static TResult Invoke<TResult> (System.Activities.Activity<TResult> workflow);
static member Invoke : System.Activities.Activity<'Result> -> 'Result
Public Shared Function Invoke(Of TResult) (workflow As Activity(Of TResult)) As TResult

Type Parameters

TResult

The type of the workflow.

Parameters

workflow
Activity<TResult>

The workflow definition of the workflow to invoke. The workflow definition needs to derive from ActivityWithResult.

Returns

TResult

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

Examples

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.

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);

Remarks

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.

Applies to

Invoke<TResult>(Activity<TResult>, IDictionary<String,Object>)

Invokes a workflow synchronously using the specified workflow definition and IDictionary<TKey,TValue> of input parameters.

public:
generic <typename TResult>
 static TResult Invoke(System::Activities::Activity<TResult> ^ workflow, System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs);
public static TResult Invoke<TResult> (System.Activities.Activity<TResult> workflow, System.Collections.Generic.IDictionary<string,object> inputs);
static member Invoke : System.Activities.Activity<'Result> * System.Collections.Generic.IDictionary<string, obj> -> 'Result
Public Shared Function Invoke(Of TResult) (workflow As Activity(Of TResult), inputs As IDictionary(Of String, Object)) As TResult

Type Parameters

TResult

The type of the workflow.

Parameters

workflow
Activity<TResult>

The workflow definition of the workflow to invoke.

inputs
IDictionary<String,Object>

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

Returns

TResult

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

Examples

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.

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);

Remarks

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.

Note

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.

Applies to

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

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

public:
generic <typename TResult>
 static TResult Invoke(System::Activities::Activity<TResult> ^ workflow, System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs, TimeSpan timeout);
public static TResult Invoke<TResult> (System.Activities.Activity<TResult> workflow, System.Collections.Generic.IDictionary<string,object> inputs, TimeSpan timeout);
static member Invoke : System.Activities.Activity<'Result> * System.Collections.Generic.IDictionary<string, obj> * TimeSpan -> 'Result
Public Shared Function Invoke(Of TResult) (workflow As Activity(Of TResult), inputs As IDictionary(Of String, Object), timeout As TimeSpan) As TResult

Type Parameters

TResult

The type of the workflow.

Parameters

workflow
Activity<TResult>

The workflow definition of the workflow to invoke.

inputs
IDictionary<String,Object>

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

timeout
TimeSpan

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

Returns

TResult

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

Examples

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.

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);

Remarks

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.

Note

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.

Applies to

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

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.

public:
generic <typename TResult>
 static TResult Invoke(System::Activities::Activity<TResult> ^ workflow, System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs, [Runtime::InteropServices::Out] System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ % additionalOutputs, TimeSpan timeout);
public static TResult Invoke<TResult> (System.Activities.Activity<TResult> workflow, System.Collections.Generic.IDictionary<string,object> inputs, out System.Collections.Generic.IDictionary<string,object> additionalOutputs, TimeSpan timeout);
static member Invoke : System.Activities.Activity<'Result> * System.Collections.Generic.IDictionary<string, obj> * IDictionary * TimeSpan -> 'Result
Public Shared Function Invoke(Of TResult) (workflow As Activity(Of TResult), inputs As IDictionary(Of String, Object), ByRef additionalOutputs As IDictionary(Of String, Object), timeout As TimeSpan) As TResult

Type Parameters

TResult

The type of the workflow.

Parameters

workflow
Activity<TResult>

The workflow definition of the workflow to invoke.

inputs
IDictionary<String,Object>

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

additionalOutputs
IDictionary<String,Object>

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

timeout
TimeSpan

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

Returns

TResult

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

Examples

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.

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);

Remarks

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.

Note

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.

Applies to