views:

6

answers:

1

I'm building an app to manage employees' holiday requests, with Windows Workflow Foundation handling the core logic. I want to develop a simple workflow that will be started when a request is created, and perform tasks based on whether the request is approved or rejected.

Once the request is created, the workflow sends out notification emails and then stops executing, waiting for a decision to made (via the HandleExternalEvent activity). I've got a service class called RequestDecisionMonitor, this implements IRequestDecisionMonitor which is marked with [ExternalDataExchange] and raises an event which contains an ExternalDataEventArgs.

The service just polls the database at a set interval, checking to see if any requests have been approved or rejected since the last check. If they have, it should raise the event which then reactivates the workflow.

The problem I've got is, when raising the event I need to pass out the instanceId of the workflow, so that the runtime can find which workflow needs activating. However, I don't know what the ID is, as it's not stored anywhere.

Do I need to persist the workflow ID in the database with a link to its holiday request? I could do that but this problems leads me to think perhaps my whole approach to this is wrong.

Any advice from WF gurus would be appreciated.

A: 

Using the WorkflowEnvironment.WorkflowInstanceId you can get the instanceId when the activity calls into your service. Save, or send it along with the request, and you can use it later to raise the event for the workflow.

Maurice