Disposed Event being fired twice.

Topics: CAB & Smart Client Software Factory
Nov 17, 2005 at 12:45 AM
originally posted by: jburkholder

In the RTW release it appears as if the Disposed event gets fired twice for views (user controls). In C# (Quickstarts) it doesn't appear to cause any harm but in VB.NET it blows up if you try to do anything in that event the second time through. Anyone else seeing this behavior?
Nov 17, 2005 at 7:41 AM
originally posted by: DLorenz

Well, this is an odd issue I had in previous versions. If you put eventsubscriptions in any SmartPart, it will receive the event, even if it is disposed. . When you terminate a workitem, the workitem and controller will disappear. However, the smartpart remains with the property IsDisposed set to true. So, if you use any EventSubscriptions in your SmartParts, you have to do:

public sub SomeMethod(...)
If Not Me.IsDisposed Then
'Do what you need to do.
End If
End Sub
Nov 17, 2005 at 8:29 AM
originally posted by: jburkholder

I'm not doing anything CAB related just trying to do some basic cleanup. It works the first time but blows up the second time through. Also why would the state object be set to Nothing by the time you hit Dispose?
Nov 17, 2005 at 9:23 AM
originally posted by: DLorenz

Do you mean you are trying to dispose the WorkItem? I don't think you are supposed to use that. You should really be using Terminate instead.
Nov 17, 2005 at 10:21 AM
originally posted by: BradWilsonMSFT

WorkItem.Terminate() and WorkItem.Dispose() are equivalent.

There is one small difference in behavior that doesn't affect normal usage. WorkItem silently protects itself against double Dispose() calls, whereas a call to change the state of WorkItem that is already terminated -- including a call to Termiante() -- will result in an exception.
Nov 17, 2005 at 12:23 PM
originally posted by: jburkholder

In the Load Event for a view (User Control) I am hooking a statechanged event from the State property of the controller. In the Disposed event I would like to unhook the event handler, first time through everything works fine, second time through the Controller.State property is set to Nothing so I have to set a boolean to not go through the second time. In the quickstarts you can put a breakpoint in the disposing method for a user control and see it breaks twice.