We had this problem in a project a while ago. The solution we came up with was to host two runtimes; one with persistence services and one without. In the runtime with no persistence service we were running a couple of this kind of "monitoring workflows" that were automatically started when the host was started.
This is how it was implemented:
First, we had a config file in which we set up the persistence service:
<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>
And in the workflow host application (cut and edited, but I think i communicates the idea):
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);
}
}