I have a client-server application in which I use classic sockets and streams to receive / send data and listen for clients.
The application works fine, but after some random time, I get an ObjectDisposedException :
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'MainForm'.
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
This code is called from the client's Socket thread, and I use the Invoke () method to run the code in the user interface thread.
I am sure that I do not manually dispose of the form and do not use Close () (the form is closed by clicking the Close button), so I do not know what could lead to its disposal.
Change : an exception is not , which is called when the form is closed - it happens by accident.
source
share