While Activity - Loss of status

Hello,

I have a custom activity having its own serializable data. When using it in a SequentialWorkflow together with a following Code activity, I'm able to query from the Code event handler the data in the custom activity.
When placing both in a Sequence in a While activity, the data in the custom activity is lost and the code activity sees my custom activity as created by constructor.
I've read that the While activity re-initializes its child activities each time it loops (can I somehow prevent this ) but my problem occurs in the sequence inside the loop, in other words, the loop executes the first time...

Thanks forward to your response.
NRN


Answer this question

While Activity - Loss of status

  • Sumit8888

    Thanks Darren for your reply!

    Obviously the context is cleared not only at the end of the iteration, but after executing each activity, in this case also my custom activity (CA). So I do not have the chance copying the data from the CA and storing it in a safe place:
    The only way to do this would be writing code in the CA that knows about the environment it is executed in.
    I would like to save my data in code inside a immediate following Code activity, but there it is already lost.

    Regards,
    NRN

  • Nick Lenting

    Set the direction of the property to in/out so that updates to the property within your custom activity are propogated to the bound property in the workflow.

  • arc_dev

    To the best of my knowledge there is no way to stop the context being cleared at the end of each iteration of the while.

    You could store the data you want to persist as fields on the workflow and bind the fields to properties on you custom activity.

    This way the data would persist for the life of the workflow.

  • milesrush

    Thanks Darren for your solution.

    I want to give below also another one I've found:


    // Code of a 'Code' activity somewhere in the start of the workflow...
    this.CA.Closed += new EventHandler<ActivityStatusChangeEventArgs> (Savior);
    ...
    // below - code inside the workflow class
    void Savior ( object sender, ActivityStatusChangeEventArgs e )
    {
      // if ( e.ForActivity == this.CA )
        this.someDataMember = (e.ForActivity as typeOfCA).SomeProperty
    }

     


    Notes: The 'While' does not execute the activities in the workflow, but copies/clonings of them. The activities we know (and have named them) are not executed inside the 'While'. Instead catching the 'Closed' event we find this 'copy' (that's why we shouldn't use the commented IF statement - it's always false inside a 'While' and always true outside).

    I can access data in my CA activity, but not through its name, not inside the 'While'. I use the argument of the event handler to get to the really executed activity...

    NRN


  • While Activity - Loss of status