Question

I'm using Visual Studio 2010 Beta 2 to get a head start on learning to use WF4. I'm working in the designer to create a xaml file. I've added a ForEach activity, and inside that ForEach activity have a flowchart that does some conditional processing. I want to be able to break out of the ForEach if one of the conditions is true, but can't figure out how to do so. In a C# code behind file that would just be to issue a break; , but in the xaml workflow designer, I don't see any mechanism for breaking from a loop. Any suggestions?

Was it helpful?

Solution

There is no break equivalent in WF4. So either you need to start adding conditional logic to skip the next loops or throw an exception and catch that outside of the ForEach and continue.

And I agree that neither is a very nice option :-(

OTHER TIPS

Using a While or DoWhile activity in place of a ForEach may be the best option for the activity's limitations on iteration control. It's a little uglier but works just as you're wanting your iteration to.

The conditional could check a bool, such as Broken, and a counter variable to compare it against the collections length. I'm not sure if this is the best for your scenario or for the collection your looping but seems like a viable option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top