Removed event not fired when WorkItem terminated

Topics: CAB & Smart Client Software Factory
Feb 28, 2006 at 2:32 PM
originally posted by: andrewjohnpeters

When terminating a WorkItem, the Removed event should fire on the parent WorkItem's Workitems collection. I think this bug is caused by the fact that WorkItem.Dispose bypasses ManagedObjectCollection.
Mar 1, 2006 at 6:37 AM
originally posted by: DLorenz

Hmmm, when I terminate workitems, the parent loses the reference to it in its WorkItem collection...
Mar 1, 2006 at 11:59 AM
originally posted by: andrewjohnpeters

>> Hmmm, when I terminate workitems, the parent loses the reference to it in its WorkItem collection...

It does, but the Removed event doesn't seem to fire. I observed this behaviour when running the sample WorkItems visualizer. From looking at the code it seems the event is only fired when an item is removed by calling Remove.
Mar 13, 2006 at 7:39 PM
originally posted by: brownap

So is there a workaround?

If you call Remove on the collection, an ArgumentException with the following message is thrown: "Removing WorkItems is not permitted. Use WorkItem.Terminate or WorkItem.Dispose to clean up a WorkItem."
Mar 14, 2006 at 10:38 AM
originally posted by: andrewjohnpeters

My workaround is to hook the Terminated event of the item itself. Note, the workitem is actually removed from the collection so there is no need to manually call Remove.