BufferedGraphicsContext 错误

发布于 2024-07-05 19:40:24 字数 1127 浏览 4 评论 0原文

在使用应用程序几个小时后,我每天都会同时收到以下错误和调用堆栈。 谁能解释一下正在发生的事情吗?

System.InvalidOperationException: BufferedGraphicsContext cannot be disposed of because a buffer operation is currently in progress.

at System.Drawing.BufferedGraphicsContext.Dispose(Boolean disposing)

at System.Drawing.BufferedGraphicsContext.Dispose()

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.ScrollableControl.WndProc(Message& m)

at System.Windows.Forms.ToolStrip.WndProc(Message& m)

at System.Windows.Forms.MenuStrip.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)

I am getting the below error and call stack at the same time everyday after several hours of application use. Can anyone shed some light on what is happening?

System.InvalidOperationException: BufferedGraphicsContext cannot be disposed of because a buffer operation is currently in progress.

at System.Drawing.BufferedGraphicsContext.Dispose(Boolean disposing)

at System.Drawing.BufferedGraphicsContext.Dispose()

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.ScrollableControl.WndProc(Message& m)

at System.Windows.Forms.ToolStrip.WndProc(Message& m)

at System.Windows.Forms.MenuStrip.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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

债姬 2024-07-12 19:40:24

MSDN 论坛对此错误进行了很长的讨论此处。 在大多数情况下,错误显然与以下任一相关:

  1. 潜在的 OutOfMemory 问题,表现为 BufferedGraphicsContext 异常,可能是由于框架错误造成的。
  2. GDI 对象泄漏(创建 GDI 对象而不释放它们)。

我记得大约一年前我自己看到了这个错误,它肯定与内存问题有关,导致我们的应用程序在长时间运行后填满了所有可用的虚拟机,所以#1 与我所观察到的一致。

There is a very long MSDN forums discussion of this error here. In most cases the error is apparently associated with either:

  1. An underlying OutOfMemory problem, which manifests as the BufferedGraphicsContext exception, possibly due to a framework bug.
  2. A GDI object leak (creating GDI objects and not disposing them).

I recall seeing this error myself a year or so ago, and it was definitely associated with a memory problem that made our app fill up all available VM after a long run, so #1 agrees with what I have observed.

春夜浅 2024-07-12 19:40:24

我知道这个问题很老了,但我遇到了同样的问题,并发现,当我使用多个实现手动双缓冲的控件时,它才出现。

对我来说,我此时发现了问题:

BufferedGraphicsContext _BackbufferContext = BufferedGraphicsManager.Current;

所以我的所有控件都使用当前上下文,我认为它始终是相同的。
在我将其替换为

BufferedGraphicsContext _BackbufferContext = new BufferedGraphicsContext();

一切后,一切都按预期进行。

我希望这有点帮助。

I know this question is old, but i had the same problem and found out, that it only showed up, when i used multiple controls which implemented manual double buffering.

For me, i found the problem at this point:

BufferedGraphicsContext _BackbufferContext = BufferedGraphicsManager.Current;

So all my controls used the Current context, which i assume is always the same.
After i replaced it by

BufferedGraphicsContext _BackbufferContext = new BufferedGraphicsContext();

everything works like wanted.

I hope this is a little bit helpfull.

为你鎻心 2024-07-12 19:40:24

黑暗中的一枪——你是用多线程绘画吗? 如果您正在做与绘画相关的工作,请在 GUI 线程上进行或仔细同步您的代码。

a shot in the dark - are you painting from multiple threads? If you are doing painting related work, do it on the GUI thread or synchronize your code carefully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文