D
David Sworder
Hi,
I have a form that displays data (is that vague enough for you?). The
data comes in on a thread-pool thread. Since the thread pool thread is not
the same as the UI thread, the callback function of my form follows the
standard design pattern:
if(IsDisposed){
return;
}
if(InvokeRequired){
this.BeginInvoke(delegateToThisMethod,new Object[]{args...});
return;
}
....painting code here.....
The idea here is: If the user has closed the form (it's disposed), then
just ignore the incoming data. If the form is still open, show the data via
some painting code, but do so on the form's UI thread. Nothing too unusual
here. My question is: What happens if BeginInvoke() is called on a form that
is already disposed? This could happen in the following situation:
In the code above, let's say that the this.BeingInvoke() call is just
about to execute, but then a context switch happens and the user's request
to close the window transpires which leads to a Dispose() call on the form.
The context then switches back to my BeginInvoke() call which would then be
made against a disposed form. Is this a problem? From my perspective, I
don't care since the 'IsDisposed' check at the top of my code should catch
this... but will WinForms internally have a problem with the fact that
BeginInvoke() is being called on a form whose window handle has been
disposed?
I have a form that displays data (is that vague enough for you?). The
data comes in on a thread-pool thread. Since the thread pool thread is not
the same as the UI thread, the callback function of my form follows the
standard design pattern:
if(IsDisposed){
return;
}
if(InvokeRequired){
this.BeginInvoke(delegateToThisMethod,new Object[]{args...});
return;
}
....painting code here.....
The idea here is: If the user has closed the form (it's disposed), then
just ignore the incoming data. If the form is still open, show the data via
some painting code, but do so on the form's UI thread. Nothing too unusual
here. My question is: What happens if BeginInvoke() is called on a form that
is already disposed? This could happen in the following situation:
In the code above, let's say that the this.BeingInvoke() call is just
about to execute, but then a context switch happens and the user's request
to close the window transpires which leads to a Dispose() call on the form.
The context then switches back to my BeginInvoke() call which would then be
made against a disposed form. Is this a problem? From my perspective, I
don't care since the 'IsDisposed' check at the top of my code should catch
this... but will WinForms internally have a problem with the fact that
BeginInvoke() is being called on a form whose window handle has been
disposed?