Kavita Kamani - MSFT

I am a PM on the Windows Workflow Foundation team, and I wanted to check with you all on when you use the CAG and what kind of scenarios you find CAG works well for you, and when it doesnt work well. I would love to hear feedback and opinions on this post.


Re: Windows Workflow Foundation What are your CAG scenarios?

Fred Morrison

I am using a CAG after going down a blind alley of trying to use a WhileActivity that contained a ParallelActivity with three 'legs' that need to run in parallel: (1) A set of "Approver" tasks, 70% (or some other designated at init time %) need to be completed (2) A set of "Reviewer" tasks, of which 100% must be completed and (3) most important, a "DueDate monitor" that "wakes up" (via DelayForActivity) every so often to see if the overall DueDate has past by.

The While/Parallel attempt failed because the ParallelActivity would freeze up inside on of the three 'legs' if that leg was waiting on something to happen (OnTaskChanged event or DelayFor activity timespan interval of about 10 minutes to finish).

The CAG turned out to be the best choice for this particular workflow because, using Code Conditions to set the When Condition for all three 'legs' allowed me to know if (1) the Approvers and Reviewers completed their tasks *BEFORE* the DueDate or (2) the DueDate *EXPIRED* before the required number of Approvers and 100% of the Reviewers had completed their tasks.

Unlike the ParallelActivity, the CAG continued to round-robin the way I would expect a "parallel" activity should work. If there is one slight performance impact, the When Condition is always evaluated, even after it first begins returning False. I'll take that 'hit' using a CAG to get the kind of 'true parallel' activity that I had hoped the ParallelActivity would have provided. From what I can tell, the ParallelActivity is pretty useless in its current non-threaded form.

The ability of each leg of the CAG to "influence" the When Condition outcome of the other two parts of the CAG was crucial to implementing this "center piece" of my custom workflow. If the tasks were completed on time, that portion of the CAG had to be able to tell the DueDate Monitor to "stop monitoring, we're done!" and, conversely, if the DueDate Monitor reached the end of the DueDate, it had to reach over and tell the Approver and Reviewer parts of the CAG that "Hey you guys! It's too late to complete any more tasks! We have to move on!".

I'm currently adding logic to the "DueDate Monitor" to allow it to auto-Complete any of the remaining uncompleted Reviewer and/or Approver tasks before allowing the CAG to finish (i.e., all three When Conditions returning False).

The final steps of the workflow are a single WssTaskActivity (taken from the ECM Starter Kit ECMActivities solution) for the so-called "Final Decision Maker" that takes into account (via Instructions) whether the CAG complete normally (i.e., tasks were completed BEFORE the DueDate vs. DueDate "expired").

-- Fred Morrison

-- Exostar

Re: Windows Workflow Foundation What are your CAG scenarios?

David Felker

We find the CAG activity do be very useful for conducting multi-step approval sequences where a rejection causes one or more previous activities to be re-completed. Using the CAG instead of the while activity greatly reduced the amount of code in one of our more complex approval sequences.

Re: Windows Workflow Foundation What are your CAG scenarios?

Fred Morrison

I'm intrigued by your use of a CAG to do things that people like David Mann almost (with religious zeal) argues are better suited to State Machine workflows.

On page 193 of his Apress book "Workflow in the 2007 Microsoft Office System", under the section "State Machine vs. Sequential - A Workflow Smackdown", David Mann makes some pretty good arguments about using State Machine workflows for just the type of "back-and-forth" situation you described.

How do you accomplish the same thing with a CAG Do you complete the original tasks and start new ones or just find the original tasks and change their status and/or due dates

My experience is that a CAG is just a nicer way to achieve true parallel execution of a number of activities (typically WssTask activities in my case)while simultaneously timing the overall completion of those tasks against an inflexible due date. In my scenario, either all the tasks are completed by the people they are assigned to prior to the due date (in which case that "timer watch dog" part of the CAG becomes irrelevant and has its When Condition set to False) or the Due Date passes and the "timer watch dog" shuts down the task portion of the CAG by setting both it's When Condition to False and its Until Condition to True. Either way, my workflow is still sequential in nature (can't "back up"); otherwise, I'd design it as a State Machine workflow.