2012-10-30 57 views
1

我有,我们有一些可怕的复杂的代码抛出了一个Win32ExceptionForm.Shown后如何引发句柄错误?

错误创建窗口句柄的问题。

望着调用堆栈我看到了堆的底部是

MainForm_ShownEvent(object sender, EventArgs e)//I Had a type-o here...arguments were wrong 
{ 
    someControl.Parent = contentPanel;//call starts here 
} 

堆栈的顶部来自一个自定义事件。事件处理程序在MainForm

anotherControl_RefreshEvent(object sender, PhysDocEventArgs e) 
{ 
    Text = titleBarText;//win32 exception 
} 

这怎么可能?我们不保证一旦调用Form.Shown就会创建句柄吗?

更新

立即窗口告诉我this.Handle为0,其中this是MainForm的对象。

堆栈跟踪(这是19页长,不得不删除一些)

System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams cp)  
    System.Windows.Forms.Control.CreateHandle() 
    System.Windows.Forms.Form.CreateHandle()  
    DevExpress.XtraEditors.XtraForm.CreateHandle() 
    System.Windows.Forms.Control.RecreateHandleCore() 
    System.Windows.Forms.Form.RecreateHandleCore() 
    System.Windows.Forms.Form.OnTextChanged(System.EventArgs e) 
    System.Windows.Forms.Control.Text.set(string value) 
    System.Windows.Forms.Form.Text.set(string value)  
> BHCS.ECC.PhysDoc.UI.Forms.MainForm.TemplateBaseControl_RefreshEvent(object sender = {BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl}, BHCS.ECC.PhysDoc.BL.PhysDocEventArgs e = {BHCS.ECC.PhysDoc.BL.PhysDocEventArgs}) Line 46 C# 
    BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RefreshControls() Line 323 C# 
    BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RunCreateControlProcess(bool destroyControls = false, bool reload = false, bool createControls = false, BHCS.ECC.PhysDoc.UI.LoadingForm loading = null) Line 1020 C# 
    BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.docNode_Resize(object sender = {BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl}, System.EventArgs e = {System.EventArgs}) Line 683 C# 
    System.Windows.Forms.Control.OnResize(System.EventArgs e) 
    System.Windows.Forms.UserControl.OnResize(System.EventArgs e) 
    BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.OnResize(System.EventArgs e = {System.EventArgs}) Line 140 C# 
    System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
    System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
    System.Windows.Forms.Control.UpdateBounds() 
    System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
    System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
    System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
    System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m)  
    System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
    System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
    System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
    [Native to Managed Transition] 
    [Managed to Native Transition] 
    System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Width) 
    System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
    System.Windows.Forms.Control.Width.set(int value) 
    BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RefreshControls() Line 332 C# 
    BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RunCreateControlProcess(bool destroyControls = false, bool reload = false, bool createControls = false, BHCS.ECC.PhysDoc.UI.LoadingForm loading = null) Line 1020 C# 
    BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.docNode_Resize(object sender = {BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl}, System.EventArgs e = {System.EventArgs}) Line 683 C# 
    System.Windows.Forms.Control.OnResize(System.EventArgs e) 
    System.Windows.Forms.UserControl.OnResize(System.EventArgs e) 
    BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.OnResize(System.EventArgs e = {System.EventArgs}) Line 140 C# 
    System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
    System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
    System.Windows.Forms.Control.UpdateBounds() 
    System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
    System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
    System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
    System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m)  
    System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
    System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
    System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
    [Native to Managed Transition] 
    [Managed to Native Transition] 
    System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Width) 
    System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
    System.Windows.Forms.Control.Width.set(int value) 
    BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RefreshControls() Line 332 C# 
    BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RunCreateControlProcess(bool destroyControls = false, bool reload = false, bool createControls = false, BHCS.ECC.PhysDoc.UI.LoadingForm loading = null) Line 1020 C# 
    BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.docNode_Resize(object sender = {BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl}, System.EventArgs e = {System.EventArgs}) Line 683 C# 
    System.Windows.Forms.Control.OnResize(System.EventArgs e) 
    System.Windows.Forms.UserControl.OnResize(System.EventArgs e) 
    BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.OnResize(System.EventArgs e = {System.EventArgs}) Line 140 C# 
    System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
    System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
    System.Windows.Forms.Control.UpdateBounds() 
    System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
    System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
    System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
    System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m)  
    System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
    System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
    System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
    [Native to Managed Transition] 
    [Managed to Native Transition] 
    System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Height)  
    System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
    System.Windows.Forms.Control.Height.set(int value) 
    BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.RefreshSize(bool setAnchorAndWidth = false) Line 109 C# 
    BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.ctrl_Resize(object sender = {System.Windows.Forms.Panel}, System.EventArgs e = {System.EventArgs}) Line 442 C# 
    System.Windows.Forms.Control.OnResize(System.EventArgs e) 
    System.Windows.Forms.Panel.OnResize(System.EventArgs eventargs) 
    System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
    System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
    System.Windows.Forms.Control.UpdateBounds() 
    System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
    System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  

(已删除的分区)

BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RefreshControls() Line 332 C# 
BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RunCreateControlProcess(bool destroyControls = false, bool reload = false, bool createControls = false, BHCS.ECC.PhysDoc.UI.LoadingForm loading = null) Line 1020 C# 
BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.docNode_Resize(object sender = {BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl}, System.EventArgs e = {System.EventArgs}) Line 683 C# 
System.Windows.Forms.Control.OnResize(System.EventArgs e) 
System.Windows.Forms.UserControl.OnResize(System.EventArgs e) 
BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.OnResize(System.EventArgs e = {System.EventArgs}) Line 140 C# 
System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
System.Windows.Forms.Control.UpdateBounds() 
System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Height)  
System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
System.Windows.Forms.Control.Height.set(int value) 
BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.RefreshSize(bool setAnchorAndWidth = false) Line 109 C# 
BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.ctrl_Resize(object sender = {System.Windows.Forms.Panel}, System.EventArgs e = {System.EventArgs}) Line 442 C# 
System.Windows.Forms.Control.OnResize(System.EventArgs e) 
System.Windows.Forms.Panel.OnResize(System.EventArgs eventargs) 
System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
System.Windows.Forms.Control.UpdateBounds() 
System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Height)  
System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
System.Windows.Forms.Control.Height.set(int value) 
BHCS.ECC.PhysDoc.Plugins.Prompt.BL.PanelPrompt.pnlOuter_Layout(object sender = {System.Windows.Forms.Panel}, System.Windows.Forms.LayoutEventArgs e = {System.Windows.Forms.LayoutEventArgs}) Line 164 C# 
System.Windows.Forms.Control.OnLayout(System.Windows.Forms.LayoutEventArgs levent = {System.Windows.Forms.LayoutEventArgs}) 
System.Windows.Forms.ScrollableControl.OnLayout(System.Windows.Forms.LayoutEventArgs levent)  
System.Windows.Forms.Control.PerformLayout(System.Windows.Forms.LayoutEventArgs args) 
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(System.Windows.Forms.Layout.IArrangedElement affectedElement, string affectedProperty) 
System.Windows.Forms.Control.OnResize(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Panel.OnResize(System.EventArgs eventargs) 
System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
System.Windows.Forms.Control.UpdateBounds() 
System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Width) 
System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
System.Windows.Forms.Control.Width.set(int value) 
BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.OnResize(System.EventArgs e = {System.EventArgs}) Line 150 C# 
System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
System.Windows.Forms.Control.UpdateBounds() 
System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Width) 
System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
System.Windows.Forms.Control.Width.set(int value) 
BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RefreshControls() Line 332 C# 
BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RunCreateControlProcess(bool destroyControls = false, bool reload = false, bool createControls = false, BHCS.ECC.PhysDoc.UI.LoadingForm loading = null) Line 1020 C# 
BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.docNode_Resize(object sender = {BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl}, System.EventArgs e = {System.EventArgs}) Line 683 C# 
System.Windows.Forms.Control.OnResize(System.EventArgs e) 
System.Windows.Forms.UserControl.OnResize(System.EventArgs e) 
BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.OnResize(System.EventArgs e = {System.EventArgs}) Line 140 C# 
System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
System.Windows.Forms.Control.UpdateBounds() 
System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Height)  
System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
System.Windows.Forms.Control.Height.set(int value) 
BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.RefreshSize(bool setAnchorAndWidth = false) Line 109 C# 
BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.ctrl_Resize(object sender = {System.Windows.Forms.Panel}, System.EventArgs e = {System.EventArgs}) Line 442 C# 
System.Windows.Forms.Control.OnResize(System.EventArgs e) 
System.Windows.Forms.Panel.OnResize(System.EventArgs eventargs) 
System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
System.Windows.Forms.Control.UpdateBounds() 
System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Height)  
System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
System.Windows.Forms.Control.Height.set(int value) 
BHCS.ECC.PhysDoc.Plugins.Prompt.BL.PanelPrompt.pnlOuter_Layout(object sender = {System.Windows.Forms.Panel}, System.Windows.Forms.LayoutEventArgs e = {System.Windows.Forms.LayoutEventArgs}) Line 164 C# 
System.Windows.Forms.Control.OnLayout(System.Windows.Forms.LayoutEventArgs levent = {System.Windows.Forms.LayoutEventArgs}) 
System.Windows.Forms.ScrollableControl.OnLayout(System.Windows.Forms.LayoutEventArgs levent)  
System.Windows.Forms.Control.PerformLayout(System.Windows.Forms.LayoutEventArgs args) 
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(System.Windows.Forms.Layout.IArrangedElement affectedElement, string affectedProperty) 
System.Windows.Forms.Control.OnResize(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Panel.OnResize(System.EventArgs eventargs) 
System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
System.Windows.Forms.Control.UpdateBounds() 
System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Width) 
System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
System.Windows.Forms.Control.Width.set(int value) 
BHCS.ECC.PhysDoc.UI.UserControls.PDDocumentNodeControl.OnResize(System.EventArgs e = {System.EventArgs}) Line 150 C# 
System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
System.Windows.Forms.Control.UpdateBounds() 
System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = Width) 
System.Windows.Forms.Control.SetBounds(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified) 
System.Windows.Forms.Control.Width.set(int value) 
BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RefreshControls() Line 332 C# 
BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.RunCreateControlProcess(bool destroyControls = false, bool reload = false, bool createControls = false, BHCS.ECC.PhysDoc.UI.LoadingForm loading = null) Line 1020 C# 
BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl.OnResize(System.EventArgs e = {System.EventArgs}) Line 1073 C# 
System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) 
System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) 
System.Windows.Forms.Control.UpdateBounds() 
System.Windows.Forms.Control.WmWindowPosChanged(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 71, System.IntPtr wparam, System.IntPtr lparam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
DevExpress.Utils.Win.Hook.ControlWndHook.WindowProc(System.IntPtr hWnd, int message, System.IntPtr wParam, System.IntPtr lParam)  
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Forms.Control.SetBoundsCore(int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified = None) 
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.SetBounds(System.Drawing.Rectangle bounds, System.Windows.Forms.BoundsSpecified specified)  
System.Windows.Forms.Layout.DefaultLayout.xLayoutDockedControl(System.Windows.Forms.Layout.IArrangedElement element, System.Drawing.Rectangle newElementBounds, bool measureOnly, ref System.Drawing.Size preferredSize, ref System.Drawing.Rectangle remainingBounds) 
System.Windows.Forms.Layout.DefaultLayout.LayoutDockedControls(System.Windows.Forms.Layout.IArrangedElement container, bool measureOnly = false)  
System.Windows.Forms.Layout.DefaultLayout.xLayout(System.Windows.Forms.Layout.IArrangedElement container = {System.Windows.Forms.Panel}, bool measureOnly = false, out System.Drawing.Size preferredSize = {Width = -7103 Height = -7105}) 
System.Windows.Forms.Layout.DefaultLayout.LayoutCore(System.Windows.Forms.Layout.IArrangedElement container, System.Windows.Forms.LayoutEventArgs args) 
System.Windows.Forms.Layout.LayoutEngine.Layout(object container, System.Windows.Forms.LayoutEventArgs layoutEventArgs) 
System.Windows.Forms.Control.OnLayout(System.Windows.Forms.LayoutEventArgs levent) 
System.Windows.Forms.ScrollableControl.OnLayout(System.Windows.Forms.LayoutEventArgs levent)  
System.Windows.Forms.Control.PerformLayout(System.Windows.Forms.LayoutEventArgs args) 
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(System.Windows.Forms.Layout.IArrangedElement affectedElement, string affectedProperty) 
System.Windows.Forms.Control.ControlCollection.Add(System.Windows.Forms.Control value = {BHCS.ECC.PhysDoc.UI.UserControls.TemplateBaseControl}) 
System.Windows.Forms.Control.ParentInternal.set(System.Windows.Forms.Control value) 
System.Windows.Forms.Control.Parent.set(System.Windows.Forms.Control value) 
BHCS.ECC.PhysDoc.UI.Forms.MainForm.MainForm_Shown(object sender = {BHCS.ECC.PhysDoc.UI.Forms.MainForm}, System.EventArgs e = {System.EventArgs}) Line 88 C# 
System.Windows.Forms.Form.OnShown(System.EventArgs e) 
System.Windows.Forms.Form.CallShownEvent() 
System.Windows.Forms.Control.InvokeMarshaledCallbackDo(System.Windows.Forms.Control.ThreadMethodEntry tme) 
System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj) 
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)  
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)  
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) 
System.Windows.Forms.Control.InvokeMarshaledCallback(System.Windows.Forms.Control.ThreadMethodEntry tme)  
System.Windows.Forms.Control.InvokeMarshaledCallbacks() 
System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) 
DevExpress.XtraEditors.XtraForm.WndProc(ref System.Windows.Forms.Message msg) 
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 
System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)  
System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 49734, System.IntPtr wparam, System.IntPtr lparam) 
[Appdomain Transition] 
[Native to Managed Transition] 
[Managed to Native Transition] 
System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame}) Line 2281 Unknown 
System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) Line 368 Unknown 
System.Windows.Threading.Dispatcher.Run() Line 327 Unknown 
System.Windows.Application.RunDispatcher(object ignore) Line 2745 C# 
System.Windows.Application.RunInternal(System.Windows.Window window) Line 1841 C# 
System.Windows.Application.Run(System.Windows.Window window) Line 261 C# 
Eclipsys.Infrastructure.UIShell.App.Main() 
+0

也许它是在有问题的窗体上的控件的句柄,而不是窗体本身的句柄。 –

+0

@SteveWellens - titleBarText是一个字符串对象。文本是“MainForm.Text”的一个属性。我相信这是不可能的,因为这行代码没有涉及任何控制。 –

+0

你可以检查句柄,这个值是多少?表单上有很多控件吗?你可以尝试暂时删除它们,看看问题是否消失。 –

回答

2

这是有异常的容易诊断和一个非常普遍的原因。开始诊断任务管理器,进程选项卡。查看+选择列,勾选USER对象。当你在它的时候,勾选GDI Objects和Handles。运行程序并在使用程序功能时观察进程的USER对象值。

如果您看到的值稳步增加,那么您的程序正在泄漏窗口句柄。一旦这个值达到10000,那么Windows就不再给它更多的窗口,这个过程已经消耗了它的配额。由此引发的异常是“创建窗口句柄时出错”。

原因是Winforms中一个非常常见的编程错误。它通过使用Controls.Remove/At()或Controls.Clear()从父项中移除控件时发生,但忘记在这些删除的控件上调用Dispose()方法。这将使他们永远活着,靠窗把手保持活力。

+0

+1我会深入研究这一点。从我们过去的错误,这听起来*很有希望! –

+0

在抛出异常的时候不是10,000。 Handles/User Objects/GDI分别为1278/1376/799。 –

+0

发布异常的完整堆栈跟踪。确保启用非托管调试并启用Microsoft符号服务器,以便我们也可以看到本机堆栈帧。 –