Bewerken

Delen via


WorkflowRuntime Constructors

Definition

Initializes a new instance of the WorkflowRuntime class.

Overloads

WorkflowRuntime()

Initializes a new instance of the WorkflowRuntime class.

WorkflowRuntime(String)

Initializes a new instance of the WorkflowRuntime class by using the specified section of the application configuration file.

WorkflowRuntime(WorkflowRuntimeSection)

Initializes a new instance of the WorkflowRuntime class by using the settings in the specified WorkflowRuntimeSection.

WorkflowRuntime()

Initializes a new instance of the WorkflowRuntime class.

public:
 WorkflowRuntime();
public WorkflowRuntime ();
Public Sub New ()

Examples

The following code example demonstrates how you can use WorkflowRuntime functionality from a workflow host. It provides an example of how to use the WorkflowRuntime constructor to create an instance of a WorkflowRuntime and access its methods and events.

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

The WorkflowRuntime is initialized with the default property values and contains the default core services. To additionally configure the workflow run-time engine, you can add and remove services by using AddService and RemoveService, and you can set Name. After the WorkflowRuntime is configured, call StartRuntime to start the workflow run-time engine and its services.

The following table shows initial property values for an instance of WorkflowRuntime class.

Property Initial Value
Name "WorkflowRuntime"
IsStarted false

The default core services are DefaultWorkflowCommitWorkBatchService and DefaultWorkflowSchedulerService.

Applies to

WorkflowRuntime(String)

Initializes a new instance of the WorkflowRuntime class by using the specified section of the application configuration file.

public:
 WorkflowRuntime(System::String ^ configSectionName);
public WorkflowRuntime (string configSectionName);
new System.Workflow.Runtime.WorkflowRuntime : string -> System.Workflow.Runtime.WorkflowRuntime
Public Sub New (configSectionName As String)

Parameters

configSectionName
String

The name of a valid workflowSettings section in the application configuration file.

Exceptions

configSectionName is a null reference (Nothing in Visual Basic).

A valid workflowSettings section could not be found in the application configuration file.

A WorkflowRuntime already exists for this application domain.

Remarks

The WorkflowRuntime is initialized according to the settings in the section specified by configSectionName in the application configuration file. configSectionName must correspond to a valid workflowSettings section of a configuration file.

When the workflow run-time engine is configured by using an application configuration file, it loads and instantiates classes of the types listed in the Services section of the configuration file. When the workflow run-time engine constructs these classes it looks for class constructors with the following signatures in the following order:

  1. Service(WorkflowRuntime runtime, NameValueCollection parameters)

  2. Service(WorkflowRuntime runtime)

  3. Service(NameValueCollection parameters)

  4. Service()

All service classes that are loaded from a configuration file must implement at least one of these constructor signatures.

For more information, see WorkflowRuntimeSection.

Applies to

WorkflowRuntime(WorkflowRuntimeSection)

Initializes a new instance of the WorkflowRuntime class by using the settings in the specified WorkflowRuntimeSection.

public:
 WorkflowRuntime(System::Workflow::Runtime::Configuration::WorkflowRuntimeSection ^ settings);
public WorkflowRuntime (System.Workflow.Runtime.Configuration.WorkflowRuntimeSection settings);
new System.Workflow.Runtime.WorkflowRuntime : System.Workflow.Runtime.Configuration.WorkflowRuntimeSection -> System.Workflow.Runtime.WorkflowRuntime
Public Sub New (settings As WorkflowRuntimeSection)

Parameters

Exceptions

settings is a null reference (Nothing in Visual Basic).

A WorkflowRuntime already exists for this application domain.

Remarks

This constructor provides a mechanism to configure the workflow run-time engine using a single method call for hosts that do not use an application configuration file. There are many reasons for not using the application configuration file. A host can run in an environment that does not allow using configuration files; for example, in trusted environments that do not allow reading from the application configuration file for security reasons. Also, a host can use a proprietary configuration mechanism; for example, the host can store the workflow run-time engine configuration settings in a SQL database.

The workflow run-time engine loads and instantiates classes of the types contained in WorkflowRuntimeSection.Services. When the workflow run-time engine constructs these classes it looks for class constructors with the following signatures in the following order:

  1. Service(WorkflowRuntime runtime, NameValueCollection parameters)

  2. Service(WorkflowRuntime runtime)

  3. Service(NameValueCollection parameters)

  4. Service()

All service classes that are specified in settings must implement at least one of these constructor signatures.

Applies to