BufferedGraphicsContext Error

I get the following error and call the stack at the same time every day after several hours of using the application. Can anyone shed 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)
+3
source share
3 answers

There is a very lengthy discussion on the MSDN forum about this error here . In most cases, the error seems to be related to either:

  • The main OutOfMemory problem, which manifests itself as a BufferedGraphicsContext exception, is probably due to a structure error.
  • Leaking a GDI object (creating GDI objects, not deleting them).

, , , , β„– 1 , .

+3

, , , , .

:

BufferedGraphicsContext _BackbufferContext = BufferedGraphicsManager.Current;

, , , , . ,

BufferedGraphicsContext _BackbufferContext = new BufferedGraphicsContext();

, .

, .

+1

shot in the dark - do you draw from multiple threads? If you are doing work related to the picture, do it in the stream of the graphical user interface or carefully synchronize your code.

0
source

Source: https://habr.com/ru/post/1696825/


All Articles