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



Answer this question

Error using WaitHandle.WaitAll() in STA thread.

  • PeterVrenken

    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

  • pvulcan

    Thread.Join doesnot help here.
  • Error using WaitHandle.WaitAll() in STA thread.