Export (0) Print
Expand All

WorkflowRuntime.StartRuntime Method

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

Namespace:  System.Workflow.Runtime
Assembly:  System.Workflow.Runtime (in System.Workflow.Runtime.dll)

public void StartRuntime()

ExceptionCondition
ObjectDisposedException

The WorkflowRuntime is disposed.

InvalidOperationException

There is more than one service workflow CommitWorkBatch service registered with this WorkflowRuntime.

-or-

There is more than one scheduler service registered with this WorkflowRuntime.

-or-

There is more than one persistence service registered with this WorkflowRuntime.

This method verifies that a valid set of core services exists and then starts any services that derive from the WorkflowRuntimeService class. There must be one and only one of each of the following core services: a workflow CommitWorkBatch service derived from the WorkflowCommitWorkBatchService base class and a scheduler service derived from the WorkflowSchedulerService base class. If either or both of these core services are missing, the workflow run-time engine supplies the appropriate default service: DefaultWorkflowCommitWorkBatchService for the workflow CommitWorkBatch service and DefaultWorkflowSchedulerService for the scheduler service. A persistence service is optional, but there can be at most only one persistence service present. After it has validated the service configuration, StartRuntime calls Start on all of the services that are derived from the WorkflowRuntimeService class. Finally, the workflow run-time engine sets IsStarted and raises the Started event.

You cannot add or remove core services after the workflow run-time engine is started. Core services are services that derive from the WorkflowSchedulerService class, the WorkflowCommitWorkBatchService class, the WorkflowPersistenceService class, or the TrackingService class. If you call StartRuntime while the workflow run-time engine is running, no action is performed.

The following code example demonstrates how to use WorkflowRuntime functionality from a workflow host. The code calls the StartRuntime after the [M:System.Workflow.Runtime.WorkflowRuntime.#ctor()] creates a WorkflowRuntime instance and after it calls AddService to add services to the runtime. It also calls StartRuntime before any other processing occurs.

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

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

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