WorkflowRuntime.StartRuntime Método

Definición

Inicia el motor en tiempo de ejecución de flujo de trabajo y los servicios correspondientes.

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

Excepciones

Hay más que un flujo de trabajo de servicio CommitWorkBatch registrado con este WorkflowRuntime.

O bien

Hay más de un servicio programador registrado con este WorkflowRuntime.

O bien

Hay más de un servicio de persistencia registrado con este WorkflowRuntime.

Ejemplos

El ejemplo de código siguiente muestra cómo se puede utilizar la funcionalidad WorkflowRuntime desde un host del flujo de trabajo. El código llama StartRuntime después de que WorkflowRuntime cree una instancia WorkflowRuntime y después llama AddService para agregar los servicios al tiempo de ejecución. También llama StartRuntime antes de que se produzca cualquier otro procesamiento.

Este ejemplo de código forma parte del ejemplo Cancelar un flujo de trabajo .

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

Comentarios

Este método comprueba que existe un conjunto válido de servicios centrales y, a continuación, inicia los servicios que derivan de la clase WorkflowRuntimeService. Debe haber uno y solo uno de los siguientes servicios principales: un servicio de flujo de trabajo CommitWorkBatch derivado de la WorkflowCommitWorkBatchService clase base y un servicio de programador derivado de la WorkflowSchedulerService clase base. Si faltan o ambos servicios principales, el motor en tiempo de ejecución del flujo de trabajo proporciona el servicio predeterminado adecuado: DefaultWorkflowCommitWorkBatchService para el servicio de flujo de trabajo CommitWorkBatch y DefaultWorkflowSchedulerService para el servicio del programador. El servicio de persistencia es opcional, pero solamente puede haber uno presente. Después de haber validado la configuración del servicio, StartRuntime llama Start en todos los servicios que se derivan de la clase WorkflowRuntimeService. Finalmente, el motor en tiempo de ejecución de flujo de trabajo establece IsStarted y genera el evento Started.

No pueden agregar o quitar los servicios centrales después de que el motor en tiempo de ejecución de flujo de trabajo se haya iniciado. Los servicios centrales son servicios que derivan de la clase WorkflowSchedulerService, la clase WorkflowCommitWorkBatchService, la clase WorkflowPersistenceService y la clase TrackingService. Si llama a StartRuntime mientras el motor en tiempo de ejecución de flujo de trabajo está en ejecución, no se realiza ninguna acción.

Se aplica a