Managing child work-Items

Topics: CAB & Smart Client Software Factory
Feb 2, 2006 at 5:19 AM
originally posted by: pariampampam


Looking at the EventBroker Quickstart, I notice that whenever "ShowList" is clicked, a new child work item is created and added to the list. But these child work items never get removed. Since thei're held in a list inside the parent work item, they never get freed by the garbage collector, so they are kept for good.

In a real-world application, having a zombie work item for each dialog once displayed seems like a serious issue, so I expect this is not the way CAB is thought to be used. Is there any guideline on how to manage such work-items?

Feb 2, 2006 at 10:32 AM
originally posted by: SamSneed

You could dispose of each workitem when you are done. Or, if you wish to reuse the workitem, give it an ID when you inject it into the Parent workitem and then execute a Get<type>(<id>) on the Parent workitem's WorkItems collection. If it returns null, then you can decide to create a new one or do something else.
Feb 2, 2006 at 11:12 PM
originally posted by: pariampampam

Where would be "the good place" to dispose it when I'm done? As I interpret it, the child work-item is created to isolate control over the usecase - so the parent work item does not know when the child is done. Or is this assumption wrong?
Feb 3, 2006 at 6:21 AM
originally posted by: SamSneed

The way things are broken out in my project there is a workitem associated with a use case. We do not limit the possibility of a workitem creating child workitems to manage other use cases that make up the larger use case. Each workitem is reponsible for managing its own resources including sub workitems (but not the child workitems' resources). When a child workitem is complete, they signal the parent workitem by firing an event with a DataEventArg that contains the child workitem's ID which then parent used to do the <workitem>.WorkItems.Get<workitemtype>(<workitemID>) and then calls Dispose().

This way, each work item manages its resources and if the Dispose/Terminate event is broadcasted globally, then each item listening for the broadcast can filter the message b/c <workitem>.WorkItems.Get<workitemtype>(<workitemID>) will return null if the ID sent does not match an ID contained in the <workitem>.WorkItems collection.
Feb 4, 2006 at 6:13 AM
originally posted by: DLorenz

To remove a child workitem, you must call Terminate() on that workitem. Then it will be removed from its parent's collection. Or you can terminate the parent workitem to get rid of all its children automatically.
Feb 4, 2006 at 6:59 AM
originally posted by: pariampampam

Thanks! This sounds better to me.