benwu's WebLog

Control.Invoke hangs under heavy stress

There have been reports of Control.Invoke hanging after the method completes.  This was reported by a few customers and we have fixed this.  For your reference:

ID: SRX050308605416

KB Article: 896665

The problem stems from some of the errors I describe in my previous post.  IsCompleted will be "true", but the AsyncWaitHandle will never be set.  The fix will be included in our next service pack.

A few workarounds exist:

1. Use a timeout in a loop checking IsComplete.  Such as:

while (!result.IsCompleted) {

   result.AsyncWaitHandle.WaitOne(200, false);

}

2. Access AsyncWaitHandle and call Thread.MemoryBarrier() before checking IsComplete

WaitHandle handle = result.AsyncWaitHandle;

Thread.MemoryBarrier();

if (!result.IsCompleted) {

   handle.WaitOne();

}

instead of:

if (!result.IsCompleted) {

   result.AsyncWaitHandle.WaitOne();

}

Both of these workarounds should work.  The first has a minor perf implication.

Props to Jack Cheng at VideoTechnics for helping to correct the second fix.

Published Thursday, May 19, 2005 1:00 PM by benwu

Comments

 

jfo's coding said:

Jack asks:

I couldn't find where to post the comment for the cross threading problem. While the solution...
May 19, 2005 2:48 PM
 

benwu s WebLog Control Invoke hangs under heavy stress | Joint Pain Relief said:

June 8, 2009 2:25 PM
 

benwu s WebLog Control Invoke hangs under heavy stress | Cellulite Creams said:

June 8, 2009 10:38 PM
 

benwu s WebLog Control Invoke hangs under heavy stress | work from home said:

June 16, 2009 8:39 AM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker