R – Windows Workflow: “singleton”-style workflow

workflowworkflow-foundation

I have a workflow that will watch certain databases and kick off other workflows when it notices a trigger. I only want one instance of this "observer" workflow to be going at any point in time; otherwise, if two or more were running, they'd both notice the change and both fire off the same workflow, which wouldn't work well.

This "observer" workflow is persisted. So…how do I make it so that if the runtime doesn't have an instance of this workflow persisted already, it starts one, but if one is already there, just use the persisted one?

Almost sounds like I could create a small run-once console app that kicked off the workflow I wanted, and then the "real" runtime just pulled the persisted one and never tries to create a new one, but that doesn't sound very elegant.

Best Answer

I'm considering this problem as well for a project I'm currently working. However it seems to me that the function of monitoring the DB is not the responsibilty of the workflow.

We're going to create a Service to add to the runtime. This service will raise events that the workflow listens for in the HandleEventActivity. That way the workflow goes idle, is persisted and stays that way until a real work actually needs doing.