locked
Are variables scoped to a sequence supposed to maintain their value across multiple iterations of the sequence? RRS feed

  • Question

  • As an example, I have a workflow that contains a ForEach activity called FE, and FE contains a Sequence activity Seq1.  In the designer, I add a variable myStrings of type Collection<String>, scope it to Seq1, and set it's default value to New Collection(Of String).

    By doing that, I would expect that every time my workflow enters Seq1, a new instance of myStrings would be created and set to an empty collection.  And that when the workflow leaves Seq1, myStrings would go out of scope and get cleaned up.

    What I'm seeing is the opposite: everytime around the loop, when the workflow enters Seq1, myStrings already contains the strings added in the previous execution of the sequence.  Is that the intended behavior?

     

    Thanks,

    Jason

    Tuesday, March 29, 2011 6:11 PM

Answers

  • I just came to this realization myself after adding some additional info to my tracking records.  Sure enough, the collection is initialized every time the sequence is entered.  It looks like the event I'm responding to in order to populate the collection is either sending more information than it should, or getting raised multiple times. So nevermind me.  Thanks for the information though.  

    Jason

    • Proposed as answer by Tim Lovell-Smith Wednesday, March 30, 2011 4:05 PM
    • Marked as answer by Andrew_Zhu Tuesday, April 5, 2011 6:58 AM
    Wednesday, March 30, 2011 3:00 PM

All replies

  • Hi Jason,
    I just quickly tried this out in a new app and it seemed to work as you expect, and not as you describe seeing. The new collection was created each time through the loop. Are you sure the variable is set to the scope of the sequence inside of the ForEach and not some other activity called Seq1?
    Tim
    Wednesday, March 30, 2011 2:43 AM
  • I just came to this realization myself after adding some additional info to my tracking records.  Sure enough, the collection is initialized every time the sequence is entered.  It looks like the event I'm responding to in order to populate the collection is either sending more information than it should, or getting raised multiple times. So nevermind me.  Thanks for the information though.  

    Jason

    • Proposed as answer by Tim Lovell-Smith Wednesday, March 30, 2011 4:05 PM
    • Marked as answer by Andrew_Zhu Tuesday, April 5, 2011 6:58 AM
    Wednesday, March 30, 2011 3:00 PM