StartRuntime Method

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

Exception Condition

The WorkflowRuntime is disposed.


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


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


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(new SqlWorkflowPersistenceService(connectionString));

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

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



.NET Framework
Available since 3.0
Return to top
© 2015 Microsoft