I am getting this exception sometimes while running my Windows Forms app for a long time:
System.ComponentModel.Win32Exception: The operation completed succe
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)
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: