WorkflowRuntime.StopRuntime 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
停止工作流程執行階段引擎和執行階段服務。
public:
void StopRuntime();
public void StopRuntime ();
member this.StopRuntime : unit -> unit
Public Sub StopRuntime ()
例外狀況
範例
下列程式碼範例示範如何從工作流程主機使用 WorkflowRuntime 功能。 在主機完成所有與執行階段相關聯的其他處理後,會呼叫 StopRuntime。
此程式碼範例是 取消工作流程 範例的一部分。
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
備註
這個方法會使工作流程執行時間引擎卸載其每個工作流程實例、停止衍生自 WorkflowRuntimeService 類別的所有服務、設定 IsStarted 為 false
,並引發 Stopped 事件。
若要正常關閉 WorkflowRuntime,請先呼叫 StopRuntime,再呼叫 Dispose。
如需詳細資訊,請參閱 Dispose 方法。