none
Exit a ForEach<T>

    Question

  • I'm trying to figure out if there is a way to exit a ForEach<T> activity.

    Inside my activity I have an If activity to check for a specific value. I have nothing in my Else statement, I'd rather just exit out and keep moving through the workflow if I find the value.

    I was thinking about:
    ForEach<T>
    ..Sequence
    ....FlowChart
    ......FlowDecision
    ........False - do nothing just let the loop continue
    ........True - somehow exit out of the ForEach

    Any ideas?


    EM
    Tuesday, December 29, 2009 5:13 PM

Answers

  • Hi,

    A couple of options...

    1) Use a boolean flag (IsForEachActive) set to true:

    ForEach<T>
      If IsForEachActive
        Sequence
          If (Need to exit)
            IsForEachActive = False
      Else

    The ForEach<T> will continue to itterate through the collection, but no action will be performed, so it should not be a big perf hit.

    2) Build a custom ForEach<T> with an exit option.

    If you create a custom activity you can change the way the ForEach<T> works. I think the ForEach<T> is sealed, so you will have to derive from something higher up. (Reflector can help to see how the ForEach<T> is written.)

    Regards

    Alan








    www.CloudCasts.net - Community Webcasts Powered by Azure
    Wednesday, December 30, 2009 9:14 AM