在使用应用程序几个小时后,我每天都会同时收到以下错误和调用堆栈。谁能解释一下正在发生的事情吗?
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)
最佳答案
MSDN 论坛对此错误有很长的讨论 here 。在大多数情况下,错误显然与以下任一相关:
- 潜在的 OutOfMemory 问题,表现为 BufferedGraphicsContext 异常,可能是由于框架错误造成的。
- GDI 对象泄漏(创建 GDI 对象而不释放它们)。
我记得大约一年前我自己看到了这个错误,它肯定与内存问题有关,导致我们的应用程序在长时间运行后填满了所有可用的虚拟机,所以#1 与我所观察到的一致。
关于winforms - BufferedGraphicsContext 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57766/