D
Dave Parker
In part of the system I am working on I have a background task (started with
a call to BeginInvoke() on a delegate), which at some point needs to read a
property from one of the controls on a form.
Normally this all works great. The problem I am having is if the user closes
the form whilst the background task is running. Execution blocks
indefinitely on the call to Control.Invoke() and the method I supply to it
never begins. The application's message queue doesn't seem busy and the UI
is still responsive other than I have this thread sitting in the background,
stuck on this call. I am calling Invoke() on a custom UserControl that has
not yet been disposed.
The stack trace to where it is blocking inside Invoke() shows up as the
following...
[In a sleep, wait, or join]
mscorlib.dll!System.Threading.WaitHandle.WaitOne(long timeout, bool
exitContext) + 0x2e bytes
mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout,
bool exitContext) + 0x23 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WaitForWaitHandle(System.Threading.WaitHandle
waitHandle = {System.Threading.ManualResetEvent}) + 0xa1 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control
caller, System.Delegate method, object[] args, bool synchronous) + 0x36d
bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate
method, object[] args) + 0x48 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate
method) + 0x7 bytes
I can get around the problem by replacing the Invoke() call with a
BeginInvoke() and therefore being able to specify a timeout, but I'm curious
as to why it's happening in the first place.
Thanks
Dave
a call to BeginInvoke() on a delegate), which at some point needs to read a
property from one of the controls on a form.
Normally this all works great. The problem I am having is if the user closes
the form whilst the background task is running. Execution blocks
indefinitely on the call to Control.Invoke() and the method I supply to it
never begins. The application's message queue doesn't seem busy and the UI
is still responsive other than I have this thread sitting in the background,
stuck on this call. I am calling Invoke() on a custom UserControl that has
not yet been disposed.
The stack trace to where it is blocking inside Invoke() shows up as the
following...
[In a sleep, wait, or join]
mscorlib.dll!System.Threading.WaitHandle.WaitOne(long timeout, bool
exitContext) + 0x2e bytes
mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout,
bool exitContext) + 0x23 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WaitForWaitHandle(System.Threading.WaitHandle
waitHandle = {System.Threading.ManualResetEvent}) + 0xa1 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control
caller, System.Delegate method, object[] args, bool synchronous) + 0x36d
bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate
method, object[] args) + 0x48 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate
method) + 0x7 bytes
I can get around the problem by replacing the Invoke() call with a
BeginInvoke() and therefore being able to specify a timeout, but I'm curious
as to why it's happening in the first place.
Thanks
Dave