OnLoad for child controls called during DockManager.Dispose

Docking/MDI for Windows Forms Forum

Posted 14 years ago by Kevin McCormick
Version: 2.0.0107
Avatar
I am having a problem similar to the one posted in

http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=778

I am working on a solution that contains a main form that contains a UserControl. This UserControl contains a DockManager and a few ToolWindows. This is not our final design as this is a prototype, but I have noticed that the OnLoad method for my UserControl is called during the Dispose of its DockManager. Naturally this is undesirable for a control to call its own OnLoad method more than once.

Why is this happening, and is there something I can do to prevent it? (Is this fixed in .108?)

Interestingly, I am attempting to reproduce the problem in a new, empty solution and am having difficulty doing so with a mostly blank solution. I'll keep trying to reproduce the problem, but is there anything in specific that could cause this to happen?

Here's the relevant part of the call stack:

MyProject.exe!MyProject.MapperControl.MapperControl_Load(object sender = {MyProject.MapperControl}, System.EventArgs e = {System.EventArgs}) Line 65 C#
System.Windows.Forms.dll!System.Windows.Forms.UserControl.OnLoad(System.EventArgs e) + 0x7a bytes
System.Windows.Forms.dll!System.Windows.Forms.UserControl.OnCreateControl() + 0x27 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible) + 0x181 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl() + 0x24 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WmShowWindow(ref System.Windows.Forms.Message m) + 0x98 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x2b6 bytes
System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) + 0x2a bytes
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) + 0x10 bytes
System.Windows.Forms.dll!System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m) + 0x10 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 24, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width, int height, System.Runtime.InteropServices.HandleRef hWndParent, System.Runtime.InteropServices.HandleRef hMenu, System.Runtime.InteropServices.HandleRef hInst, object pvParam) + 0x3c bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams cp) + 0x225 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateHandle() + 0x125 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.Handle.get() + 0x45 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.HostedInWin32DialogManager.get() + 0x80 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.HostedInWin32DialogManager.get() + 0x49 bytes
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WmSetFocus(ref System.Windows.Forms.Message m = {msg=0x7 (WM_SETFOCUS) hwnd=0xf043c wparam=0x12044e lparam=0x0 result=0x0}) + 0x39 bytes
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) + 0x17 bytes
ActiproSoftware.UIStudio.Dock.Net20.dll!ActiproSoftware.UIStudio.Dock.TabbedMdiWindow.WndProc(ref System.Windows.Forms.Message m = {msg=0x7 (WM_SETFOCUS) hwnd=0xf043c wparam=0x12044e lparam=0x0 result=0x0}) + 0x6c bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 7, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.FocusActiveControlInternal() + 0xdf bytes
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.AfterControlRemoved(System.Windows.Forms.Control control = {ToolWindow[Key=]}, System.Windows.Forms.Control oldParent = {ToolWindowContainer[]}) + 0x1ab bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlCollection.Remove(System.Windows.Forms.Control value) + 0xc8 bytes
ActiproSoftware.UIStudio.Dock.Net20.dll!cr.c(System.Windows.Forms.Control A_0 = {ToolWindow[Key=]}) + 0x6a bytes
ActiproSoftware.UIStudio.Dock.Net20.dll!ActiproSoftware.UIStudio.Dock.ToolWindowContainer.b(ActiproSoftware.UIStudio.Dock.ToolWindow A_0 = {ToolWindow[Key=]}) + 0x349 bytes
ActiproSoftware.UIStudio.Dock.Net20.dll!ActiproSoftware.UIStudio.Dock.DockManager.a(ActiproSoftware.UIStudio.Dock.TabbedMdiWindow[] A_0 = {ActiproSoftware.UIStudio.Dock.TabbedMdiWindow[1]}, bool A_1 = true) + 0x74e bytes
ActiproSoftware.UIStudio.Dock.Net20.dll!ActiproSoftware.UIStudio.Dock.DockManager.a(ActiproSoftware.UIStudio.Dock.TabbedMdiWindow[] A_0 = {ActiproSoftware.UIStudio.Dock.TabbedMdiWindow[1]}, bool A_1 = true, ActiproSoftware.UIStudio.Dock.TabbedMdiWindowCloseReason A_2 = DockManagerDisposing) + 0xf5 bytes
ActiproSoftware.UIStudio.Dock.Net20.dll!ActiproSoftware.UIStudio.Dock.DockManager.CloseAllActiveToolWindows(bool force = true, ActiproSoftware.UIStudio.Dock.TabbedMdiWindowCloseReason reason = DockManagerDisposing) + 0xf7 bytes
ActiproSoftware.UIStudio.Dock.Net20.dll!ActiproSoftware.UIStudio.Dock.DockManager.CloseAllActiveToolWindows(bool force = true) + 0x83 bytes
ActiproSoftware.UIStudio.Dock.Net20.dll!ActiproSoftware.UIStudio.Dock.DockManager.Dispose(bool disposing = true) + 0x260 bytes
System.dll!System.ComponentModel.Component.Dispose() + 0x12 bytes
System.dll!System.ComponentModel.Container.Dispose(bool disposing) + 0x92 bytes
System.dll!System.ComponentModel.Container.Dispose() + 0x12 bytes
MyProject.exe!MyProject.MapperControl.Dispose(bool disposing = true) Line 18 + 0xf bytes C#
System.dll!System.ComponentModel.Component.Dispose() + 0x12 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.Dispose(bool disposing = true) + 0x199 bytes
System.dll!System.ComponentModel.Component.Dispose() + 0x12 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.Dispose(bool disposing = true) + 0x199 bytes
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.Dispose(bool disposing) + 0x1f bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.Dispose(bool disposing) + 0x273 bytes
MyProject.exe!MyProject.Form1.Dispose(bool disposing = true) Line 20 + 0xc bytes C#

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kevin,

It's hard to say what is happening without debugging it and even then this sort of thing could be tricky. However from the stack trace it looks like we are removing some control, and Microsoft's code ends up trying to focus something else that has already been disposed. Thus it ends up recreating that control again. That's what it looks like at least.

How about if you try moving focus outside of the entire docking layout before calling DockManager.Dispose. See if that helps. My guess is that it would since then there is no need to move focus around when a control that could have focus is removed.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.