У нас была эта проблема в проекте некоторое время назад. Решение, которое мы придумали, состояло в том, чтобы разместить две среды выполнения; один с постоянными услугами и один без. Во время выполнения без службы персистентности мы выполняли несколько таких «рабочих процессов мониторинга», которые автоматически запускались при запуске хоста.
Вот как это было реализовано:
Сначала у нас был файл конфигурации, в котором мы настраивали службу персистентности:
<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);
}
}