WorkflowRuntime 构造函数

定义

初始化 WorkflowRuntime 类的新实例。

重载

WorkflowRuntime()

初始化 WorkflowRuntime 类的新实例。

WorkflowRuntime(String)

使用应用程序配置文件的指定节初始化 WorkflowRuntime 类的新实例。

WorkflowRuntime(WorkflowRuntimeSection)

使用指定的 WorkflowRuntime 中的设置初始化 WorkflowRuntimeSection 类的新实例。

WorkflowRuntime()

初始化 WorkflowRuntime 类的新实例。

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

示例

下面的代码示例演示如何使用工作流主机中的 WorkflowRuntime 功能。 它提供了有关如何使用 WorkflowRuntime 构造函数来创建 WorkflowRuntime 实例并访问其方法和事件的示例。

此代码示例是 取消工作流示例的一 部分。

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

注解

WorkflowRuntime 是以默认属性值进行初始化的,包含默认的核心服务。 若要另外配置工作流运行时引擎,可以通过使用 AddServiceRemoveService 来添加和移除服务,还可以设置 Name。 配置 WorkflowRuntime 后,调用 StartRuntime 以启动工作流运行时引擎及其服务。

下表显示 WorkflowRuntime 类的实例的初始属性值。

属性 初始值
Name "WorkflowRuntime"
IsStarted false

默认核心服务是 DefaultWorkflowCommitWorkBatchServiceDefaultWorkflowSchedulerService

适用于

WorkflowRuntime(String)

使用应用程序配置文件的指定节初始化 WorkflowRuntime 类的新实例。

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)

参数

configSectionName
String

应用程序配置文件中有效的 workflowSettings 节的名称。

例外

configSectionName 为空引用(在 Visual Basic 中为 Nothing)。

在应用程序配置文件中无法找到有效的 workflowSettings 节。

此应用程序域已存在 WorkflowRuntime

注解

根据应用程序配置文件中的 WorkflowRuntime 所指定节中的设置初始化的 configSectionNameconfigSectionName 必须与配置文件的有效 workflowSettings 部分相对应。

使用应用程序配置文件配置工作流运行时引擎时,它将加载并实例化配置文件的 节中列出的 Services 类型的类。 工作流运行时引擎构造这些类时,将按以下顺序查找使用以下签名的类构造函数:

  1. Service(WorkflowRuntime 运行时,NameValueCollection 参数)

  2. Service(WorkflowRuntime 运行时)

  3. Service(NameValueCollection 参数)

  4. Service()

从配置文件加载的所有服务类至少必须实现这些构造函数签名之一。

有关详细信息,请参阅 WorkflowRuntimeSection

适用于

WorkflowRuntime(WorkflowRuntimeSection)

使用指定的 WorkflowRuntime 中的设置初始化 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)

参数

例外

settings 为空引用(在 Visual Basic 中为 Nothing)。

此应用程序域已存在 WorkflowRuntime

注解

此构造函数提供了一个机制,可对不使用应用程序配置文件的宿主使用单一方法调用来配置工作流运行时引擎。 不使用应用程序配置文件的原因很多。 宿主可以在不允许使用配置文件的环境中运行,例如在受信任环境中由于安全原因不允许从应用程序配置文件读取数据。 此外,宿主可以使用专有的配置机制;例如,宿主可以将工作流运行时引擎的配置设置存储在 SQL 数据库中。

工作流运行时引擎将会加载 WorkflowRuntimeSection.Services 中所含类型的类并将其实例化。 工作流运行时引擎构造这些类时,将按以下顺序查找使用以下签名的类构造函数:

  1. Service(WorkflowRuntime 运行时,NameValueCollection 参数)

  2. Service(WorkflowRuntime 运行时)

  3. Service(NameValueCollection 参数)

  4. Service()

settings 中指定的所有服务类至少必须实现这些构造函数签名之一。

适用于