DockPanelWorkspace's SmartPartClosing event raises twice

Aug 19, 2009 at 2:11 AM

I placed a DockPanelWorkspace on the shell form. In the AfterShellCreated of ShellApplication.cs, I registered the RootWorkItem.Initialized event:

RootWorkItem.Initialized += new EventHandler(RootWorkItem_Initialized);
private void RootWorkItem_Initialized(object sender, EventArgs args)
{
    foreach (KeyValuePair<string, IWorkspace> key in RootWorkItem.Workspaces)
    {
        key.Value.SmartPartClosing += new EventHandler<WorkspaceCancelEventArgs>(smartPart_OnClosing);
    }
}
void smartPart_OnClosing(object sender, WorkspaceCancelEventArgs e)
{
    if (MessageBox.Show("Close?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
    {
        e.Cancel = true;
    }
}

When I click the close button at the top right corner of the dock panel, the MessageBox in the smartPart_OnClosing raised normally. If I answer No, everything looks fine, the Closing event is cancelled successfully and the smartpart still there. But when I answer Yes, this event will raise again, this time whatever I answer Yes or No, the smartpart will be disposed, is this a bug? and is there any workaround?