I have a Dialog type form that starts a worker thread,
allows the thread to update its progess and provides a
Cancel button. Following advice from Chad Meyers in a
recent posting, the worker thread updates the dialog by
calling Invoke which runs the UI update method on the UI
thread. This works nicely. (Thanks Chad)
However, if I close the dialog using the form close button
([x] top right hand corner) I get an
ObjectDisposedException when calling Invoke on the Dialog
form. So I remove the Form.ControlBox, attempting to
force the user to cancel and/or close the dialog using my
buttons. This fixes the [x] problem, but I'm still able to
close the form using Alt/F4. In this case, the Form
closes (the window disappears and the Closing event
fires), but Dispose() is not called. My worker thread
continues to run and call Invoke, apparently without
problem.
I can easily signal the worker thread to quit from the
Closing event, but I'm nervous since I don't really
understand what's going on. The documentation for
Form.ControlBox states that "If your form does not display
a control box, the form is not able to close using the
ALT+F4 keyboard combination."
My form seems to be closing but not disposing. What's
going on?
Many thanks