WorkflowRuntime.StartRuntime Method

Starts the workflow runtime engine and the workflow runtime 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.

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 runtime 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 runtime engine sets IsStarted and raises the Started event.

You cannot add or remove core services after the workflow runtime engine has been 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 runtime engine is running, no action is performed.

The following code example demonstrates how you can 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 SDK sample from the Program.cs file. For more information, see Canceling a Workflow.

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft