Suppose I have some information received on asynchronous sockets (therefore exits some background threads) , that continuously update a form. How could I safely update the form content so that I avoid the ObjectDisposedException that is sometimes thrown when I close the form ?
In the update operation (carried on the background thread) I check for the form's property IsDisposed, but this is useless as the UI thread sometimes disposes the form immediately after the check and right before the update operation causing the exception to be thrown (when I close the form) I've tried to use a lock on the form object in the form's "onScreenFormClosed" handler and on the update operation to ensure that these operation are not executed simultaneously , but this blocks the UI thread .
I even tried to run the update operation on the UI thread, but it was to no use as calling Invoke(...) on the form still throwed the ObjectDisposedException .