Error using WaitHandle.WaitAll() in STA thread.

I have a WinForm application that is declaring Main() with [STAThread] attribute. To optimizing performance I'm using worker threads and rely on WaitHandle.WaitAll() for synchronization. The code compiles but will raise a "NotSupported" exception stating "WaitAll for multiple handles on a STA thread is not supported". This does not seen to be an unreasonable task. Any ideas on why this error occurs? Any solutions?

[561 byte] By [Troup] at [2007-12-16]
# 1
Not sure what optimizing performance has to do with WaitHandle.WaitAll() though.

Anyway, You can't use WaitHandle.WaitAll() on an STA thread as WaitAll is a blocking call , this is done to prevent the message pump to run. This is not allowed in Win32 and as such neither in .NET. Use one of the other Synchronization primitives like WaitOne or Thread.Join which do a limiited amount of pumping.

Willy

MVPUser at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Thread.Join doesnot help here.
Sandeepn75 at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified