I have a problem with the current application.
(Unfortunately, this is delayed debugging - I only have this stack trace. I have never seen this in person and cannot reproduce it).
I get this exception:
message=Cannot access a disposed object. Object name: 'Button'. exceptionMessage=Cannot access a disposed object. Object name: 'Button'. exceptionDetails=System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Button'. at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.Control.get_Handle() at System.Windows.Forms.Control.PointToScreen(Point p) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.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) exceptionSource=System.Windows.Forms exceptionTargetSite=Void CreateHandle()
It looks like the mouse event appears on the form after the form has been deleted.
Please note that this stack trace does not have my code.
The only strange thing (?) That I do is that I use Dispose () forms quite aggressively when I use them with ShowModal () (see below).
EDIT: Just for clarification, I use the C ++ - CLI, so in fact I don't call Dispose () I use the delete operator. This is the same as calling Dispose ().
But I only do this after returning ShowModal () (should it be safe?) And only when I am done with the form.
I think I read that events can be queued in the event queue, but I cannot believe that this will be a problem. I mean, should the structure be tolerant of old messages? I can well imagine that with stressful messages it can go back and, of course, the window can go away at any time?
Any ideas?
If you can even suggest ways to play, this might be helpful.
John
Besides
TBH I never understood whether the call to Dispose () after Form.ShowDialog () is strictly necessary - the MSDN documents for ShowDialog (), in my opinion, are a bit ambiguous.