WorkflowRuntime.StopRuntime Method

Definition

Stops the workflow run-time engine and the run-time services.

C#
public void StopRuntime();

Exceptions

The WorkflowRuntime is already disposed of.

Examples

The following code example demonstrates how to use WorkflowRuntime functionality from a workflow host. StopRuntime is called after the host has completed all other processing associated with the runtime.

This code example is part of the Canceling a Workflow sample.

C#
static void Main()
{
    string connectionString = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;";

    using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
    {
        ExternalDataExchangeService dataService = new ExternalDataExchangeService();
        workflowRuntime.AddService(dataService);
        dataService.AddService(expenseService);

        workflowRuntime.AddService(new SqlWorkflowPersistenceService(connectionString));
        workflowRuntime.StartRuntime();

        workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
        workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
        workflowRuntime.WorkflowIdled += OnWorkflowIdled;
        workflowRuntime.WorkflowAborted += OnWorkflowAborted;

        Type type = typeof(SampleWorkflow1);
        WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
        workflowInstance.Start();

        waitHandle.WaitOne();

        workflowRuntime.StopRuntime();
    }
}

Remarks

This method causes the workflow run-time engine to unload each of its workflow instances, stop all of its services that are derived from the WorkflowRuntimeService class, set IsStarted to false, and raise the Stopped event.

To shut down the WorkflowRuntime gracefully, call StopRuntime before you call Dispose.

For more information, see the Dispose method.

Applies to

Tuote Versiot
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1