Windows Workflow Foundation 4.0 Break Out of ForEach<T> Activity
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?
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 :-(
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.
精彩评论