Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am making the following assumptions:</p> <ol> <li>This code is a method in a Form (System.Windows.Forms.Form).</li> <li>The variable 'listBox1' is a ListBox control on the form.</li> <li>You are receiving the ObjectDisposedException when the form is closed.</li> <li>You are running this method on a separate thread (not shown in the code, but implied by the question).</li> </ol> <p>I would guess that your code is blocking on the receiveFrom() call on the socket when the form is closed. The next message that arrives from the network causes receiveFrom to return, after which you put the message received into a listbox that no longer exists. The first time you access this listbox is code line "this.listBox1.Text" when creating the StringBuilder, which is the line that raises the ObjectDisposeException. The listBox is the object that is likely disposed, although it could also be the Form at this point, depening on how fast messages are coming in.</p> <p>There appears to be plenty that needs to be done, but I am not sure what is proper advice. I would first validate my assumptions 1-4 above, then look into refactoring your application such that it does NOT use multiple threads. I make this suggestion because I must assume this is not the only "threading" issue your application may have. I certaintly may be incorrect in that assumption, in which case you can ignore the answer.</p> <p>If I restrict the "what needs to be done" part of your question to a more limited scope, then I would advise to properly shutdown your UDP receiver before allowing the window to close, again assuming my assumptions are correct.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload