Re: I think I know why setstyle double buffering cases invalidOperationExceptions!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



This is interesting because I've suspected for some time that double
buffering is broken and I've seen exceptions due to the use of automatic
double buffering on several occasions. It would be great to nail this down
and post it as a real bug report with MS.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Garry Freemyer" <garryfre@xxxxxxxxxxxxxxxxxxx> wrote in message
news:uS1UbjWdFHA.3808@xxxxxxxxxxxxxxxxxxxxxxx
> Here is some of the points and observations about my screensaver, where I
> am being tortured by the InvalidOperationException raised from
> System.Graphics.EndContainer(). Here is what I think is happening. Does
> the stack trace below bear this out? Is there a method to tell the control
> when to copy it's backbuffer to the screen, and when NOT to, but to wait?
>
> 1. The manual double buffering never crashes. In this kind of buffering
> there is no double buffer between the graphics object, and the display,
> and so there is no guess work about when the drawn lines and Images that
> are loaded and displayed because they are loaded when the paint event
> argument is told to load the image, it displays it right away.
>
> 2. I noticed that even tho I specify a particular swarm to appear on
> screen, instead of appearing within seconds of each other because the
> drawing is fast. So, things drawn are not displayed immediately when using
> the SetStyle DoubleBuffer, true);
>
> 3. The contol's built in double buffering is automatic in that the control
> has a backbuffer, that you have little control over! In this scenario the
> control has to guess when it's time to copy the backbuffer to the display
> and also guess when it's time to clear it's backbuffer and the only metric
> it has, is a couple of hints in the flush method, and the next slot of
> idle time.
>
> So, that's it!! The control under double-buffering via the setstyle is
> deciding to flush the buffer out to the screen just before my program
> tries to start drawing to it! The control tries to end container on the
> bitmap, but the bitmap is still being drawn to!
>
> This would explain the delaytime where I have seven swarms on the screen,
> but one only appears every 4 seconds, till they are all on-screen.
>
> If this is raising an event, that eventually turns into a paint event,
> then, the thread could be blocking itself by invoking threads.
>
> So, the event is being caused by the bad guesswork about when a buffer is
> to be drawn and disposed of! In every error there is this message about
> something trying to access the buffer while it's being disposed!
>
> Since this drawing is so fast, it also explains why it can take hours for
> the exception to show its ugly face because the program is like a slightly
> drunken person tripping over it's own feet!
>
> I'm a bit surprised that there aren't or that I've not found in any
> double-buffering articles, a command to tell the graphic to stop guessing
> around and copy and dispose of the backbuffer when I tell it that it's
> time to.
>
> Here is the trace ...
>
> See the end of this message for details on invoking
> just-in-time (JIT) debugging instead of this dialog box.
>
> ************** Exception Text **************
> System.InvalidOperationException: The object is currently in use
> elsewhere.
> at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
> at
> System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer
> buffer)
> at System.Windows.Forms.GraphicsBuffer.Dispose()
> 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.ContainerControl.WndProc(Message& m)
> at System.Windows.Forms.Form.WndProc(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
> at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
>
>
>
> --
> To reply to this message take off the .NoJunkSpam off of the end of
> garryfre@xxxxxxxxxxxxxxxxxxxxxx
>


.



Relevant Pages

  • Re: I think I know why setstyle double buffering cases invalidOperationExceptions!
    ... auto-double buffering or manual buffering, and the first works, the second ... somehow taking control away and putting up that cursed dialog box. ... The fact that GDI+ take away my ability to control when the backbuffer is ... >> Here is some of the points and observations about my screensaver, ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: I think I know why setstyle double buffering cases invalidOperationExceptions!
    ... > to the screensaver and send it to them, there is a config option, where I ... > chose auto-double buffering or manual buffering, and the first works, the ... Showing how using flat 32 unmanaged code that gives ME control over ... > The fact that GDI+ take away my ability to control when the backbuffer is ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Generic Error in GDI+ related to DrawLine
    ... if it's a standard control and not a custom one then something else ... I do suspect a bug in the double buffering system that I can't put my finger ... Find great Windows Forms articles in Windows Forms Tips and Tricks ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: How to create a duble buffer transparent control
    ... On my second thought you can't use double buffering with transparent ... > protected override void Dispose(bool disposing) { ... >> To create a double buffered control the styles that you need to turned on>> are ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Double Buffering and Initial Paint
    ... > when I turn on double buffering ... ... > the control which is being double buffered momentarily has the same ... > When this is set to false, flickering once again occurs, but the ... > my app, but STILL not have any flicker. ...
    (microsoft.public.dotnet.framework.windowsforms)