Exit a ForEach<T>


  • 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:
    ........False - do nothing just let the loop continue
    ........True - somehow exit out of the ForEach

    Any ideas?

    Tuesday, December 29, 2009 5:13 PM


  • Hi,

    A couple of options...

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

      If IsForEachActive
          If (Need to exit)
            IsForEachActive = False

    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.)



 - Community Webcasts Powered by Azure
    Wednesday, December 30, 2009 9:14 AM