异常“创建窗口句柄时出错”恰好在工具条上使用了combobox [英] Exception "Error when creating window handle" happens to combobox on toolstrip

查看:100
本文介绍了异常“创建窗口句柄时出错”恰好在工具条上使用了combobox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我正在开发一个基于.Net 2.0 / C#的大型WinForm应用程序,有一个稳定可重现的错误"创建窗口句柄时出错" ;在笔记本电脑上运行应用程序时戴尔E6520(Win7 Pro SP1,8G RAM), 虽然它适用于台式机
机器(包括XP,Win7,2008)。

Hi, I'm working on a large WinForm application based on .Net 2.0/C#, there's a steadily reproducible error "Error when creating window handle" when running the application on laptop Dell E6520 (Win7 Pro SP1, 8G RAM),  while it works well on desktop machines (including XP, Win7, 2008).

这是异常堆栈:

System.ComponentModel .Win32Exception:创建窗口句柄时出错。

  在System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)

  在System.Windows.Forms.Control.CreateHandle()

  在System.Windows.Forms.ComboBox.CreateHandle()

  在System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

  在System.Windows.Forms.Control.CreateControl()

  在System.Windows.Forms.Control.ControlCollection.Add(控制值)

  在System.Windows.Forms.WindowsFormsUtils.ReadOnlyControlCollection.AddInternal(控制值)

  在System.Windows.Forms.ToolStripControlHost.SyncControlParent()

  在System.Windows.Forms.ToolStripControlHost.OnParentChanged(ToolStrip oldParent,ToolStrip newParent)

  在System.Windows.Forms.ToolStripItem.set_ParentInternal(ToolStrip value)

  在System.Windows.Forms.ToolStripSplitStackLayout.LayoutHorizo​​ntal()

  在System.Windows.Forms.ToolStripSplitStackLayout.LayoutCore(IArrangedElement容器,LayoutEventArgs layoutEventArgs)

  在System.Windows.Forms.Layout.LayoutEngine.Layout(对象容器,LayoutEventArgs layoutEventArgs)

  在System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)

  在System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)

  在System.Windows.Forms.ToolStrip.OnLayout(LayoutEventArgs e)

  在System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)

  在System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement,String affectedProperty)

  在System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout,IArrangedElement elementCausingLayout,String property)

  在System.Windows.Forms.Control.OnResize(EventArgs e)

  在System.Windows.Forms.Control.OnSizeChanged(EventArgs e)

  在System.Windows.Forms.Control.UpdateBounds(Int32 x,Int32 y,Int32 width,Int32 height,Int32 clientWidth,Int32 clientHeight)

  在System.Windows.Forms.Control.UpdateBounds()

  在System.Windows.Forms.Control.WmWindowPosChanged(消息& m)

  在System.Windows.Forms.Control.WndProc(消息& m)

  在System.Windows.Forms.ScrollableControl.WndProc(消息& m)

  在System.Windows.Forms.ToolStrip.WndProc(消息& m)

  在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m)

  在System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息& m)

  在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)

System.ComponentModel.Win32Exception: Error creating window handle.
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.ComboBox.CreateHandle()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.ControlCollection.Add(Control value)
   at System.Windows.Forms.WindowsFormsUtils.ReadOnlyControlCollection.AddInternal(Control value)
   at System.Windows.Forms.ToolStripControlHost.SyncControlParent()
   at System.Windows.Forms.ToolStripControlHost.OnParentChanged(ToolStrip oldParent, ToolStrip newParent)
   at System.Windows.Forms.ToolStripItem.set_ParentInternal(ToolStrip value)
   at System.Windows.Forms.ToolStripSplitStackLayout.LayoutHorizontal()
   at System.Windows.Forms.ToolStripSplitStackLayout.LayoutCore(IArrangedElement container, LayoutEventArgs layoutEventArgs)
   at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
   at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.ToolStrip.OnLayout(LayoutEventArgs e)
   at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
   at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
   at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
   at System.Windows.Forms.Control.OnResize(EventArgs e)
   at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
   at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
   at System.Windows.Forms.Control.UpdateBounds()
   at System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

当表单显示在里面有一个包含组合框和按钮的工具条时,会发生这种情况。它们稍后在构建表单后动态添加到工具条中,同时保持不可见, 通过调用下面的方法:

It happens when the form is shown where inside there's a toolstrip containing comboboxes and buttons. They are later added into toolstrip dynamically after the form is constructed while kept invisible,  by calling method below:


private void Init()
{
  ...
  foreach (ToolBarItemConfig item in configuredToolbarItems)
  {
      ToolStripItem toolStripItem = createToolStripItem(item);
      toolStrip.Items.Add(toolStripItem);
      if (toolStripItem is ToolStripComboBox)
         populateComboBox(toolStripItem as ToolStripComboBox, item); // populate items of ToolStripComboBox
  }
  ...
}

推荐答案

没有人对此提示吗?

No hint on this from anyone?

另外我可以确认问题不是由于允许的最大值处理(每个过程10k)超出。在任务管理器中观察到的实际用户对象和句柄数约为1.2k。

In addition I could confirm the problem is not due to allowed maximum handle (10k per process) exceeded. Actual User Objects and Handle count is around 1.2k as observed in Task Manager.


这篇关于异常“创建窗口句柄时出错”恰好在工具条上使用了combobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆