views:

434

answers:

1

This seems like a simple problem: I have a WF4 activity that guides the user through a set of questions. After each question is displayed, the activity should be idled until the question is answered. After each question is answered, I want to prompt the user with the next question. (The next question is determined based on the answer to the previous question.)

To do this, I have a simple workflow activity that implements a Bookmark. I have a console app running the workflow using WorkflowApplication.Run, waiting for input, and then calling .ResumeBookmark.

What I need to do is to get the value of Current_Question_Text from the workflow when it becomes idle. I've set the WorkflowApplication.Idle property to a delegate and in that delegate, I'd like to get the text of the current question stored within the Activity. However, the output arguments are not available until the Completed method fires and the WorkflowApplicationIdleEventArgs don't provide any information about the current state of data.

I've also looked at the Activity and WorkflowApplication variables in the Idle delegate and cannot see any way to get to the data that way.

Is there anyway to get data values from the Activity while it is idle?

Thanks, David Burgett

+1  A: 

There are a couple of ways you can do this. What works best depends on the circumstances.

  1. Explicitly save the variable to some external place like a database and have the client read it from there. Easy to do using a custom activity but adds another disconnect to your application.
  2. Use workflow persistence and property promotion to extract the value and store it in the workflow instance store. The promoted properties are not the nicest to work with and it requires using a WorkflowInstanceStore. Also the value is only updated when the workflow is persisted.
  3. Using a custom workflow tracking extension and extracting the value using a ActivityStateQuery. I suspect this would be the easiest approach to take in a lot of cases.
Maurice
Thank you Maurice! Option 3 was exactly what I was looking for!I created a custom tracking extension which fired when my activity went idle. It then threw an event which my application handled, updating the UI with the text of the next question. Perfect!
dburgett