Event Subscriptions and Terminated WorkItems

Topics: CAB & Smart Client Software Factory
Feb 16, 2006 at 6:06 AM
originally posted by: Saramcc

I have a workitem and a workitem controller. The controller has some event publications and subscriptions. I start the workitem and I see in the EventTopic class the event subscriptions and publications being added. Everything is fine, the workitem does what it's supposed to. Then the workitem is done and it is disposed.

Now the workitem is started again -- a new workitem (and controller) are created since it was disposed. This is fine. But, when the workitem is being started, in the EventTopic class the publications and subscriptions for the first instance of the workitem are still there. So this second run of the workitem adds them again. This causes the event subscriptions to hit twice this second time around.

The problem multiplies as the workitem is ended and restarted.

I see another thread from November 16 (Issue with Subscription and Terminated WorkItems ) that appears to be the same issue. However, I am finding that add GC.Collect() does not seem to fix my issue.

I am noticing that an event subscription that was added through a smartpart used by the workitem is being removed when I close the workitem. However, the subscriptions that are contained within the workitem controller are not being removed.

I have tried to to an EventTopics.Remove in the WorkItem OnDispose, but this throws an exception. Why is an EventTopic kept from being removed from a WorkItem?

Any suggestions for a workaround for this will be much appreciated. I'll update this if I find something. Thanks.
Feb 16, 2006 at 11:11 AM
originally posted by: Saramcc

Ok, I think I have fixed my issue. I found that if I place the event subscription and publication code directly in my workitem class or in my smartpart class, things seem to work fine -- meaning, the eventTopics are removed when the workitem or smartpart is disposed.

The problem occurs when the event code is in the workitem controller or smartpart controller.
Feb 16, 2006 at 1:27 PM
originally posted by: BradWilsonMSFT

It sounds like the controller is not being disposed and removed from the WorkItem. You will need to do that yourself, as CAB does not provide automated help here.

You can see one of our potential solutions to this issue in the SC-BAT release this coming Friday, where we tackle this problem in the context of views and presenters.