Random header image... Refresh for more!

Windows Workflow Quick Tip

Given that I spent all day looking for this and had trouble finding it (Okay, I’ll be honest, I skipped a page in the book because it didn’t look relevant, but whatever), if you ever need to get the name of the currently executing state on a Windows Workflow (WF) State Machine Workflow, there’s a class you can use called StateMachineWorkflowInstance.  StateMachineWorkflowInstance has a property called CurrentStateName to give you the name as a string and another called CurrentState, which gives you an instance of the StateActivity object that’s currently running.

For some reason unknown to me, StateMachineWorkflowInstance isn’t derived from WorkflowInstance ((Cause, you know, .Net is all object orienty and such, so that’s what I would’ve done…)), so the WorkflowInstance you get back from WorkflowRuntime.CreateWorkflow can’t be cast to a StateMachineWorkflowInstance instance.  Instead, you have to new up the object yourself.  The constructor takes the WorkflowRuntime where the workflow is executing, and the Guid returned by the InstanceId property on the WorkflowInstance that was returned by CreateWorkflow for the workflow you want to know the state for.

0 comments

There are no comments yet...

Kick things off by filling out the form below.

Leave a Comment