views:

199

answers:

2

How do I determine from the host if a workflow instance has compled or not besides subscribing to the WorkfloRuntime's WorkflowCompleted event? Is there any flag or state I can check for a given WorflowInstance to determine if it has completed?

@Edit: The question is about sequential workflows.

+1  A: 

You can to check TrackingServices to know what current state for a workflow instance.

There are some code snippets here: .NET 3.0 State Machines In Windows Workflow .

Rubens Farias
Thanks for your help! From what I see the 'completness' check can be implemented using a TrackingService, but used for just this purpose it seems a bit cumbersome, even more than the event approach. And the two approaches look similar in the sense that you have to subscibe beforehand, you can't just grab an arbitrary workflow instance and get its state. However if it works and WWF is designed this way it should not be a problem. I'm just curious why there's so little info in the WorkfloInstance itself, there should be a reason
axk
Another option is to use `System.Workflow.Activities.StateMachineWorkflowInstance` combined to `WorkflowInstance.GetWorkflowDefinition()` to tell if `smwi.CurrentState` is final state.
Rubens Farias
A: 

The answer (at least for know, from what I've learned) is that there's no flag associated with a WorkflowInstance that you can retrieve for a given instance indicating whether the instance has completed.

The two approaches available are:

  1. WorkflowRuntime.WorkflowCompleted Event

  2. Using a TrackingService service to keep a 'log' of workflow execution and quering the log to destermine if a workflow instance has completed. Here is a good introductory atricle. With this approach the only available out-of-the-box implementation of TrackingService is SqlTrackingService, which requires a SQL Server database. You can then use SqlTrackingQuery to query the 'log'

Note: An interesting aspect of the behaviour of SqlTrackingService is that it won't by default immediatly write the messages it receives from the runtime to the database, but only at the end of transactions. This behaviour is controlled by IsTransactional property of SqlTrackingService.

axk