views:

88

answers:

3

The workflow is being published as a wcf service, and I need to guarantee that workflows execute sequentially. Is there a way--in code or in the config--to guarantee the runtime doesn't launch two workflows concurrently?

A: 

You probably will need to check at workflow start for another running instance. If found, cancel it.

Rubens Farias
What I would like to do is queue them. And if two workflows are launched at the same time, this would create a concurrency issue, as both could find that they were the only one running. This really needs to be handled at the workflow runtime level, it seems, but I don't know how to accomplish that when it's being hosted in a wcf service.
Brian
A: 

There is no way to configure the runtime to limit the number of workflows in progress.

Consider though that its the responsibility of the workflow itself to control flow. Hence the workflow itself should have means to determine if another instance of itself is currently in progress.

I would consider creating an Activity that would transactionally attempt to update a DB record to the effect that an instance of this workflow is in progress. If it finds that another is currently in progress it could take the appropriate action. It could fail or it could queue itself using an EventActivity to be alerted when the previous workflow has completed.

AnthonyWJones
Thank you. That should work perfectly.
Brian
A: 

I don't agree that this needs to be handled at the WorkflowRuntime level. I like the idea of a custom Activity, sort of a MutexActivity that would be a CompositeActivity that has a DB backend. The first execution would log to the database it has a hold of the mutex. Subsequent calls would queue up their workflow IDs and then go idle. When the MutexActivity completes, it would release the Mutex, load up the next workflow in the queue and invoke the contained child activities.

Rich