views:

469

answers:

1

I'm working with the the Release Candidate of Visual Studio 2010 using Wf4 to write a new workflow for approving resource requests. In my workflow, I would like for a request to expire after a few days if no approval has been made for the request. We did this in WF 3.5 (Visual Studio 2008) by adding a Delay timer into an EventDrivenActivity parallel to the EventDrivenActivity that was awaiting an approver to come and approve the request. If the Delay expired before an approval was made, the EventDrivenActivity would terminate the request. Does anyone know if there is a similar mechanism for doing this in WF4?

+1  A: 

In WF4 this is done in the same way using a Pick activity. A Pick has multiple PickBranch children, each with a Trigger and an Action. The Trigger for each is executed and will contain the Delay, Receive or whatever else you are waiting for. The Action than contains whatever needs to be executed. Only the Action associated with the first Trigger to complete is executed, the other triggers will be canceled and the other actions skipped.

Maurice
Maurice, Thanks for the post! I've changed my workflow to include a Pick activity with 2 branches, one of which is the delay with a TimeSpan.FromSeconds(30), but after 30 seconds nothing happens. Do I need to host my workflow with the WorkflowServiceHost for this to work? I'm trying to host the workflow with WorkflowApplication.
Russ Clark
Maurice, I just set up a test Workflow Console project with a pick activity and 2 branches, one of which had a short delay and a WriteLine activity to write a message. That worked, just as you said, but I think it worked because my hosting Console application was still running. My real application is an ASP.Net MVC app, and it generates my Workflow (with the delay in the branch of the pick activity) and then the hosting app is done, and terminates. Is this what is causing problems, and is there some way to use the pick/branch/delay in a workflow hosted by a web app?
Russ Clark
What are ou using to host the workflow? In the case of a WorkflowApplication you are responsible for reloading a workflow once it has been unloaded. If you sre using a WorkflowServiceHost it will reload the workflows for you from the persitence store. I would suggest using the latter and use WCF to send messages from your ASP.NET MVC app to the workflow service.
Maurice
Maurice, I am currently using the WorkflowApplication, but will start looking into how to use WorkflowServiceHost and WCF, I'm not very familiar with either of them, so I have a lot of learning to do. When you talk about messages from the MVC app to the workflow service do you mean something similar to the Dictionary<string,object> arguments passed into the constructor for the WorkflowApplication, or is that something entirely different?
Russ Clark
The messages are SOAP messages you send using WCF. With the WorkflowServiceHost you normally start and communicate with workflows using WCF.
Maurice