Form somehow

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.

+3
source share
2 answers

Have you tried to override the method Disposeand set a breakpoint there? The column is likely to give you an indication of why / where it is located.

+1
source

I had a similar problem, I just hid the form and never closed it or never used it.

The main reason for creating the form was caused by the DialogResult button of the Cancel button , which actually forced the Close form, and then dispose was implicit.

, beaviour DialogResult .

0

Source: https://habr.com/ru/post/1747738/


All Articles