共用方式為


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 為 null 參考 (在 Visual Basic 中為 Nothing)。

在應用程式組態檔中找不到有效的 workflowSettings 區段。

已存在此應用程式定義域的 WorkflowRuntime

備註

根據 WorkflowRuntime 在應用程式組態檔中指定之區段中的設定初始化 configSectionNameconfigSectionName 必須對應至組態檔的有效 workflowSettings 區段。

使用應用程式組態檔設定工作流程執行時間引擎時,它會載入並具現化組態檔區段中所列 Services 類型的類別。 工作流程執行階段引擎建構這些類別時,會依序使用下列特徵標記尋找類別建構函式:

  1. Service(WorkflowRuntime runtime, NameValueCollection parameters)

  2. Service(WorkflowRuntime runtime)

  3. Service(NameValueCollection parameters)

  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 為 null 參考 (在 Visual Basic 中為 Nothing)。

已存在此應用程式定義域的 WorkflowRuntime

備註

這個建構函式為不使用應用程式組態檔的主機提供了一個機制,可使用單一呼叫方法來設定工作流程執行階段引擎。 不使用應用程式組態檔的原因很多。 主機可能在不允許使用組態檔的環境中執行,例如,基於安全因素而不允許從應用程式組態檔中讀取的受信任環境。 此外,主機可能想要使用專屬的組態機制,例如,主機可能將工作流程執行階段引擎組態設定儲存在 SQL 資料庫中。

工作流程執行階段引擎會載入 WorkflowRuntimeSection.Services 包含型別的類別,並將這些類別個體化。 工作流程執行階段引擎建構這些類別時,會依序使用下列特徵標記尋找類別建構函式:

  1. Service(WorkflowRuntime runtime, NameValueCollection parameters)

  2. Service(WorkflowRuntime runtime)

  3. Service(NameValueCollection parameters)

  4. Service()

所有在 settings 中指定的服務類別必須至少實作這些建構函式簽章中的其中一個。

適用於