<p>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?</p>

<pre><code>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&amp; m)

at System.Windows.Forms.Control.WndProc(Message&amp; m)

at System.Windows.Forms.ScrollableControl.WndProc(Message&amp; m)

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

at System.Windows.Forms.MenuStrip.WndProc(Message&amp; m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
</code></pre>

[{'answer_id': 57820, 'author': 'qbeuek', 'author_id': 5348, 'author_profile': 'https://Stackoverflow.com/users/5348', 'pm_score': 0, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 58132, 'author': 'McKenzieG1', 'author_id': 3776, 'author_profile': 'https://Stackoverflow.com/users/3776', 'pm_score': 3, 'selected': True, 'text': '<p>There is a very long MSDN forums discussion of this error <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=200483&amp;SiteID=1" rel="nofollow noreferrer">here</a>. In most cases the error is apparently associated with either:</p>\n\n<ol>\n<li>An underlying OutOfMemory problem, which manifests as the BufferedGraphicsContext exception, possibly due to a framework bug.</li>\n<li>A GDI object leak (creating GDI objects and not disposing them).</li>\n</ol>\n\n<p>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.</p>\n'}, {'answer_id': 21282876, 'author': 'TheQaa', 'author_id': 2028568, 'author_profile': 'https://Stackoverflow.com/users/2028568', 'pm_score': 0, 'selected': False, 'text': '<p>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.</p>\n\n<p>For me, i found the problem at this point:</p>\n\n<pre><code>BufferedGraphicsContext _BackbufferContext = BufferedGraphicsManager.Current;\n</code></pre>\n\n<p>So all my controls used the <em>Current</em> context, which i assume is always the same.\nAfter i replaced it by</p>\n\n<pre><code>BufferedGraphicsContext _BackbufferContext = new BufferedGraphicsContext();\n</code></pre>\n\n<p>everything works like wanted.</p>\n\n<p>I hope this is a little bit helpfull.</p>\n'}]
['https://Stackoverflow.com/questions/57766', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4770/']