संपादित करें

इसके माध्यम से साझा किया गया


WorkflowRuntime.StartRuntime Method

Definition

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

public:
 void StartRuntime();
public void StartRuntime ();
member this.StartRuntime : unit -> unit
Public Sub StartRuntime ()

Exceptions

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.

Examples

The following code example demonstrates how to use WorkflowRuntime functionality from a workflow host. The code calls the StartRuntime after the WorkflowRuntime 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();
    }
}
Shared Sub Main()
    Dim connectionString As String = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;"
    Using workflowRuntime As New WorkflowRuntime()
        Dim dataService As New ExternalDataExchangeService()
        workflowRuntime.AddService(dataService)
        dataService.AddService(expenseService)

        workflowRuntime.AddService(New SqlWorkflowPersistenceService(connectionString))


        AddHandler workflowRuntime.WorkflowCompleted, AddressOf OnWorkflowCompleted
        AddHandler workflowRuntime.WorkflowTerminated, AddressOf OnWorkflowTerminated
        AddHandler workflowRuntime.WorkflowIdled, AddressOf OnWorkflowIdled
        AddHandler workflowRuntime.WorkflowAborted, AddressOf OnWorkflowAborted


        Dim workflowInstance As WorkflowInstance
        workflowInstance = workflowRuntime.CreateWorkflow(GetType(SampleWorkflow))
        workflowInstance.Start()

        waitHandle.WaitOne()

        workflowRuntime.StopRuntime()
    End Using
End Sub

Remarks

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.

Applies to