前段時間我們在一個項目中遇到了這個問題。我們提出的解決方案是主辦兩個運行時間;一個具有持久性服務,另一個沒有。在沒有持久性服務的運行時,我們運行了幾種這種「監視工作流程」,這些工作流程在主機啓動時自動啓動。
這是它是如何實現的:
首先,我們必須在我們成立了持久性服務的配置文件:
<configuration>
<configSections>
<section name="RuntimeWithPersistence" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<RuntimeWithPersistence>
<CommonParameters/>
<Services>
<add type="System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionString="[dbconnectionstring]" UnloadOnIdle="true"/>
</Services>
</RuntimeWithPersistence>
</configuration>
而且在工作流宿主應用程序(剪切和編輯,但我想我傳達的想法):
public class WorkflowHost
{
private WorkflowRuntime _runtime = null;
private WorkflowRuntime _nonPersistingRuntime = null;
private void SetupRuntime()
{
// create a new WorkflowRuntime that points out a config section
// defining a persistence service
_runtime = new WorkflowRuntime("RuntimeWithPersistence");
// set up additional services to use
_runtime.StartRuntime()
// create a new WorkflowRuntime that does not point out a config section
_nonPersistingRuntime = new WorkflowRuntime();
// set up additional services to use
_nonPersistingRuntime.StartRuntime()
// start monitoring workflows in the non persisting runtime
StartMonitoringWorkflows(_nonPersistingRuntime);
}
}
感謝您的反饋!我也開始採用這種方法,但我試圖找到一個優雅的解決方案來解決另一個問題:監控人員必須知道哪些「觸發」它是之前被解僱的,因此下一次不會再這樣做它看到它。這就是爲什麼我在考慮在監視器中使用持久性的原因,因此它可以存儲一個觸發器列表,以忽略它已經執行的操作。我喜歡這個主意,並會更徹底地進行調查。 – Chris 2009-06-11 16:01:27