Need help! - accessing disposed object
-
When I dispose Control calling Control.Dispose() method, deactivate window and then re-activate window, I get
ObjectDisposedException
. Does anybody know how to avoid Windows.Forms creating handle of a disposed control? -
When I dispose Control calling Control.Dispose() method, deactivate window and then re-activate window, I get
ObjectDisposedException
. Does anybody know how to avoid Windows.Forms creating handle of a disposed control?If I'm reading this right. You have a form with a control, and then in your code you dispose of the control? So when you try to activate the window it throws the exception about the disposed object? That's because your form thinks it still exists when you go to re-activate the window. Before you dispose the object, you should remove it from the form with form.controls.remove(yourControl). Then you can dispose of the object all you want.
-
If I'm reading this right. You have a form with a control, and then in your code you dispose of the control? So when you try to activate the window it throws the exception about the disposed object? That's because your form thinks it still exists when you go to re-activate the window. Before you dispose the object, you should remove it from the form with form.controls.remove(yourControl). Then you can dispose of the object all you want.
When I use Controls.Remove(Control), the form start to working weird. It seems to be inactive (light blue) and blinking when clicked, but still keeping inactive. I also tried to use SuspendLayout() and ResumeLayout() methods. Nothing changed. And when all things worked (I had to remove more controls), Windows.Forms already tried to access correctly REMOVED and DISPOSED object calling its CreateHandle() method. The last thing I've done was to change design of my app. I have no more time to solve these bugs, maybe later. Thanks for answer!