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?
Might also have something to do with memory fragmentation. We use an unmanaged component in out app as well, and there may be issues with not being able to allocate a large enough buffer for the double-buffered graphics, when the unmanaged component has eaten all the large contiguous blocks.
I once had a similar exception, when creating a huge PictureBox. It seems that I could not allocate a Graphics big enough. Actually, what I was doing was drawing some sort of map for a simple game, and I had a zoom in functionality, that basically created a bigger buffer and then I redrawed all the graphics in a bigger scale. Playing with this zoom in function for a long time or to a deep enough level caused this exception. Perhaps you are creating lots of Graphics and not dispossing them, or just a Graphic big enough to not be allocatable.