Properly close SmartParts in DeckWorkspace

Topics: CAB & Smart Client Software Factory
Jan 25, 2006 at 9:29 PM
originally posted by: WateryDan

Hi,

I have a DeckWorkspace which I attach SmartParts to. SmartParts here are just normal UserControls.

Whenever I try to close a SmartPart on the DeckWorkspace, it is not really closed. I tested this by re-adding the same SmartPart I closed and the OnLoad method does not fire.

Is there a way I can guarantee the SmartPart UserControl is being properly closed and when I re-add it again, the OnLoad will fire?
Jan 27, 2006 at 6:59 PM
originally posted by: WateryDan

I've tried a few ways to get around this but none of them worked. I've also tried to call the Dispose() method on Workspace.ActiveSmartpart. But when I want to show the same SmartPart again, CAB complains it cannot use a control that's already disposed. Strangely, the actual SmartPart reference is still available inside the WorkItem.

I have a few UserControls that contains thousands of records so I really need to remove them from memory when they are not used.

Anyone has a work around or is this the default behavior of CAB?
Jan 27, 2006 at 8:13 PM
originally posted by: amishah_2001

This is working perfectly fine :)
Just you are missing to remove the view from the workspace before disposing it...

//close the view from the workspace
contentWorkspace.Close(view);
//removes it from the items as we have added before
this.Items.Remove(view);
//dispose it as it is must required
view.Dispose();
Jan 28, 2006 at 5:10 AM
originally posted by: DLorenz

The real question is why are you closing SmartParts and relaunching them without terminating the workitem and running it again instead?

The main reason it won't work is because if you check the view.IsDisposed, it will say true. I am guessing that when you add the smartpart into the WorkItem.SmartPart collection, you don't provide a unique key. If you want to run the same SmartPart twice, you will need a unique key, so CAB knows which one to activate.
Jan 30, 2006 at 12:42 PM
originally posted by: WateryDan

Thanks Dlorenz...

My issue is my WorkItem is responsible for many views. Even though I want to relaunch a SmartPart I cannot just deactivate and reactivate the WorkItem because there maybe other views shown in the ShellForm that is controlled by that WorkItem.