This project has moved and is read-only. For the latest updates, please go here.

Dispose in MDIWorkspace(Reprint)

Jun 24, 2008 at 5:45 PM
Hello!!.
I am using SCSF 2008.

I am trying close an smartpart MDI of two manners (X button and Close button).

I have captured the smartpartclosing event from WorkSpace to make some verificationes before closing (and user confirm).

this is the code in WorkItem:



        public void RunWorkItem()
        {
            frmDetalleClientes newfrmDetalleClientes = SmartParts.AddNew<frmDetalleClientes>("frmDetalleClientes");
           
            info = new WindowSmartPartInfo();

            Workspaces[WorkspaceNames.ModalWindows].Show(newfrmDetalleClientes, info);

            Workspaces[WorkspaceNames.ModalWindows].SmartPartClosing += new EventHandler<Microsoft.Practices.CompositeUI.SmartParts.WorkspaceCancelEventArgs>(DetalleClienteWI_SmartPartClosing);

            newfrmDetalleClientes.Disposed += new EventHandler(newfrmDetalleClientes_Disposed);
        }

        void DetalleClienteWI_SmartPartClosing(object sender, Microsoft.Practices.CompositeUI.SmartParts.WorkspaceCancelEventArgs e)
        {
            if (e.SmartPart == newfrmDetalleClientes)
            {
                if (newfrmDetalleClientes.Modified())
                {
                    DialogResult result = MessageBox.Show("Desea grabar los cambios? ",
                        Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                    switch (result)
                    {
                        case DialogResult.Yes:
                            newfrmDetalleClientes.Guardar();
                            break;
                        case DialogResult.No:
                            break;
                        case DialogResult.Cancel:
                            e.Cancel = true;
                            break;
                        default:
                            Debug.Assert(false, "The default case is not allowed!");
                            break;
                    }
                }
            }
        }

        void newfrmDetalleClientes_Disposed(object sender, EventArgs e)
        {
            if (this != null && Status != WorkItemStatus.Terminated)
            {
                Terminate();
            }
        }


this stuff works perfectly if I press the X button of the form.



In frmDetalleClientes View, I call at _presenter.OnCloseView();

        public void OnCloseView()
        {
            base.CloseView();
        }

But the View not is disposed

I tried with

        public void OnCloseView()
        {
            base.CloseView();
            WorkItem.Terminate();
        }

but if the user selects Cancel in the dialog showing in SmartPartClosing...the view close...(for the Workitem.Terminate()).


I noticed that when pressed X Button, this fires the View Dispose event , but when OnCloseView is called, not fires this event.. this is a bug or should I put some magic code in some place..

Regards!!
Oct 10, 2008 at 4:37 PM
Hi,

according to SCSF for VS 2005, this was not a bug but a known issue of the the WindowWorkspace close sequence. When you run the OnCloseView the proccess removes the SmartPart from the WindowWorkspace so CAB not need to dispose it when closing the WindowWorkspace.

You can always create a class that inherits from WindowWorkspace and give it the functionality you wish if you don't want to change original code of CAB.