This article describes how to implement an
InvokeWorkflow completed event. This article includes the following sections:
- Add code for the InvokeWorkflow completed event.
- Check the completion.
When you use an activity that has an
InvokeWorkflow control in a workflow, the workflow completed
event happens after the invoked workflow is completed or after the invoker
workflow is completed.
Add code for the InvokeWorkflow completed event
When you use the following code for the completed event, the
program stops after one workflow is completed.
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
waitHandle.Set();
};
If you want to see the execution and the result of all the workflows
that are running, you have to set the
WaitHandle event for each workflow. This includes the invoked workflows and
the invoker workflow. You then have to set the
WaitOne event for each workflow.
Note You can create the
WaitHandle event together with the
AutoResetEvents event by using the following code.
AutoResetEvent waitHandle = new AutoResetEvent(false);
For a workflow that has one invoke workflow, you can use the following
code to implement the workflow.
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
waitHandle.Set();
};
// In the hosting code, wait two times.
waitHandle.WaitOne(); // This waits for the invoked workflow to be completed.
waitHandle.WaitOne(); // This waits for the host workflow to be completed. Note Two workflows are completed: the hosting workflow and the invoked
workflow.
Check the completion
To check a completion for a particular instance, use the following
code.
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
if (e.WorkflowInstance.InstanceId == DESIRED_INSTANCE_ID)
waitHandle.Set();
};For the main workflow, you can use the
WorkflowInstance.InstanceId property to check the completion of the invoker
workflow.