Problem with state in workitems

Topics: CAB & Smart Client Software Factory
Sep 15, 2005 at 10:00 PM
originally posted by: andersmh

I have several workitems which use state.

When i create my workitems i use the constructor with a state object as a parameter, before adding them to the component collection using the Add() method.

I use async loading av of data which sets state variables with the data objects.
The workitems use the state_changed event to be notified of when the data has changed.

My problem is this;

I have 2 workitems that share the same state.

But; Only 1 workitem can have bot the get and set accessors to the state variable. Which makes sense since i think that 1 workitem "owns" the state reference to it.

But when i create my second workitem, with a state that already HAS the data in it, the state variables are not initialised with a reference to the state data.

This is not a problem when the data is later set in the state variable, since the state_changed event triggers and i then set the state variable in the workitem manually from the eventargs.value .

But in this case the workitem is created with a state with all data preloaded, and the state variables then is <null>. But when i check in the State , with a watch, the data is in the state. Just the reference to it has not been set.

So in my load_methods which sets the gui i get null-reference errors accessing the state variables.

Is this behaviour by design, meaning i have to check on the constructor/load method if the state is already set, and myself set the references to the correct data,

or is this a bug which will be fixed ?

I hope i made this understandable for you to read, and i am hopeful someone can give me some hints to what to do.

Best regards,
Anders