System.ComponentModel.Win32Exception:操作已成功完成 [英] System.ComponentModel.Win32Exception: The operation completed successfully

查看:3044
本文介绍了System.ComponentModel.Win32Exception:操作已成功完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此异常,有时运行时,我的Windows窗体应用程序很长一段时间:

I am getting this exception sometimes while running my Windows Forms app for a long time:

System.ComponentModel.Win32Exception: The operation completed successfully
   at System.Drawing.BufferedGraphicsContext.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)
   at System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
   at System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
   at System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
   at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DataGridView.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)

可能是什么原因呢?

What could be the cause for this?

推荐答案

只是为了概括起来讲,自定义网格我写的,是基于.NET的DataGridView中,使用自定义code绘制细胞。在我的网格行可以跨多个可视页面。 (这是一个业务需求)

Just to sum it up, the custom grid I wrote, that is based on the .Net's DataGridView, uses custom code to draw cells. Rows in my grid can span multiple visual pages. (That was a business requirement)

的问题是,净$ P $对 - 分配存储缓冲器,用于控制与DoubleBuffering启用。对于DataGridViews网格上的缓冲区需要相当大,以适应电网可能较大的行。在极端的情况下,一排可以跨越高达32000像素(因为一个.NET限制)。网格宽度在项目通常是500和800像素之间。 因此,所产生的缓冲即可(32bpp的* 800 * 32000 =〜100MB)

The problem was that .Net pre-allocates a buffer of memory for controls with DoubleBuffering enabled. For DataGridViews grids the buffer needs to be rather large to accommodate possible large rows in the grid. In extreme cases a row can span up to 32000 pixels (because of a .net limitation). Grid widths in the project are usually between 500 and 800 pixels. So the resulting buffer can be (32bpp * 800 * 32000 = ~100MB)

因此​​,在短期中,系统不能创建兼容的图形对象,因为偶尔,它不能保留的缓冲器足够大,以适应所需的数据。

So in short, the system could not create compatible graphics objects, because occasionally, it could not reserve a buffer large enough to fit the required data.

要解决它,我已经向大家介绍了一系列的优化:

To fix it I had to introduce a series of optimizations:

  • 在我的自定义网格允许1500像素的限制最大行高
  • 更新缓冲区重新分配code到只执行时,新缓冲区大小大于现有的
  • 确保了缓冲区不重新分配与每一个数据绑定和preallocated到一个合理的规模。
  • 在审查了所有code和确信,非托管资源的正确不使用时,建议在这里设置,:<一href="http://nomagichere.blogspot.com/2008/03/systemcomponentmodelwin32exception-is.html">http://nomagichere.blogspot.com/2008/03/systemcomponentmodelwin32exception-is.html

这篇关于System.ComponentModel.Win32Exception:操作已成功完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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