Control.Invoke call hangs worker thread

G

Guest

I've spent the last couple of weeks trying to get to the bottom of a thread
that hangs. We have a form-based application that updates some data once per
minute using a System.Threading.Timer. Inside the spawned thread, we are
using Control.Invoke to call methods on home grown objects. After running
for anywhere from several hours to a day, we see the data update thread hang
at one of these Control.Invoke calls. Using WinDbg, we have determined it is
not a deadlock because we can see that only one thread has a lock. Further,
that thread appears to be stuck on a WaitOneNative call that apparently
happens as part of the Invoke process. It is important to note that we have
seen the Invoke call hang when calling empty (noop) methods on our objects as
well as methods that contain code. Here is a stack trace of the offending
thread:

0x039ecb5c 0x7c90eb94 [FRAME: ECallMethodFrame] [DEFAULT] Boolean
System.Threading.WaitHandle.WaitOneNative(I,UI4,Boolean)
0x039ecb70 0x799ef0b7 [DEFAULT] [hasThis] Boolean
System.Threading.WaitHandle.WaitOne()
0x039ecba4 0x7b853fc4 [DEFAULT] [hasThis] Object
System.Windows.Forms.Control.MarshaledInvoke(Class
System.Windows.Forms.Control,Class System.Delegate,SZArray Object,Boolean)
0x039ecc48 0x7b881b19 [DEFAULT] [hasThis] Object
System.Windows.Forms.Control.Invoke(Class System.Delegate,SZArray Object)
0x039ecc58 0x7b881ae2 [DEFAULT] [hasThis] Object
System.Windows.Forms.Control.Invoke(Class System.Delegate)
0x039ecc5c 0x08fa5cad [DEFAULT] [hasThis] Void
Manager.Dashboard.UpdateWxData(Object)
at [+0x5c55] [+0x2217] Dashboard.cs:2289
0x039eeed4 0x02cb335d [DEFAULT] [hasThis] Void
Manager.Dashboard.timerWx_Tick(Object)
at [+0x18d] [+0xc6] Dashboard.cs:16707566
 
N

Naveen

It could probably be illegal cross thread operation. If you are using
Whidbey this can be easily identified by running under debug mode.
Whidbey uses MDA (Managed Debugging Assistant) to warn you on this.
MDA's are turned of in release builds. Also look at the !dae on the
memory dump to check if there are SEHExceptions which can help you
identifying any illegal cross thread operation.
 
W

William Stacey [MVP]

Did you try Control.BeginInvoke to see if it still happens as just a test?
Invoke is a blocking call, so if the UI thread is blocked on something else,
your worker will block waiting for result. In this way, your worker and UI
could dead-lock each other. How fast is the Timer going off? Could you
provide a small sample to repo the issue?

--
William Stacey [MVP]

| I've spent the last couple of weeks trying to get to the bottom of a
thread
| that hangs. We have a form-based application that updates some data once
per
| minute using a System.Threading.Timer. Inside the spawned thread, we are
| using Control.Invoke to call methods on home grown objects. After running
| for anywhere from several hours to a day, we see the data update thread
hang
| at one of these Control.Invoke calls. Using WinDbg, we have determined it
is
| not a deadlock because we can see that only one thread has a lock.
Further,
| that thread appears to be stuck on a WaitOneNative call that apparently
| happens as part of the Invoke process. It is important to note that we
have
| seen the Invoke call hang when calling empty (noop) methods on our objects
as
| well as methods that contain code. Here is a stack trace of the offending
| thread:
|
| 0x039ecb5c 0x7c90eb94 [FRAME: ECallMethodFrame] [DEFAULT] Boolean
| System.Threading.WaitHandle.WaitOneNative(I,UI4,Boolean)
| 0x039ecb70 0x799ef0b7 [DEFAULT] [hasThis] Boolean
| System.Threading.WaitHandle.WaitOne()
| 0x039ecba4 0x7b853fc4 [DEFAULT] [hasThis] Object
| System.Windows.Forms.Control.MarshaledInvoke(Class
| System.Windows.Forms.Control,Class System.Delegate,SZArray Object,Boolean)
| 0x039ecc48 0x7b881b19 [DEFAULT] [hasThis] Object
| System.Windows.Forms.Control.Invoke(Class System.Delegate,SZArray Object)
| 0x039ecc58 0x7b881ae2 [DEFAULT] [hasThis] Object
| System.Windows.Forms.Control.Invoke(Class System.Delegate)
| 0x039ecc5c 0x08fa5cad [DEFAULT] [hasThis] Void
| Manager.Dashboard.UpdateWxData(Object)
| at [+0x5c55] [+0x2217] Dashboard.cs:2289
| 0x039eeed4 0x02cb335d [DEFAULT] [hasThis] Void
| Manager.Dashboard.timerWx_Tick(Object)
| at [+0x18d] [+0xc6] Dashboard.cs:16707566
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top