[Mono-dev] Control.Dispose glitch?

Rob Wilkens robwilkens at gmail.com
Fri Jun 1 00:48:59 UTC 2012


(This is re: System.Windows.Forms)

IT appears Control.Dispose is destroying the parent window, then 
destroying the children...  Is it supposed to do that?

This is causing some warning messages from X11 in my test code under 
some circumstances, at least when the window is created under another 
thread and it takes the "if (this.InvokeRequired)"==true path (which 
happens when the control was created in a different thread.)  I haven't 
tried to see if other paths lead to this.

The code still runs (no crash), but I get the following warning from X11:
X11 Error encountered:
   Error: BadWindow (invalid Window parameter)
   Request:     4 (0)
   Resource ID: 0x3C0002C
   Serial:      544
....(etc)....

The events leading up to this are (all from same call to Control.Dispose 
for the form):
(1) An XDestroyWindow is sent to the Form which contained the label 
(From DestroyHandle() call path in Control.Dispose).. This succeeds.
(2) An XDestroyWindow is sent to the label when the children[] are being 
disposed (which eventually gets back to their Control.Dispose of their 
own, which then calls DestroyHandle()),and the child label has probably 
already been 'destroyed' by virtue of Destroying the parent form, and 
the result is the BadWindow message above.

I can fix this, I think, by moving the parent delete below the children 
deletion...  I haven't tested this yet, or tried doing it yet. I'm 
worried because this is not platform specific code, it may break 
something on a non-x11 platform, which means in addition to Linux, i'll 
have to test this change on my mac and my Windows installations 
somehow), presuming i make this change.  I've not yet ever built mono on 
either of those other two plaforms.

Can someone tell me I shouldn't do this?  I'm not touching anything else 
tonight.

-Rob


More information about the Mono-devel-list mailing list