S h o r t S t o r i e s

// Tales from software development

"WaitAll for multiple handles on an STA thread is not supported"

leave a comment »

My previous post, Waiting on multiple threads, mentioned Joe Duffy’s approach to synchronising multiple threads using a single WaitHandle. I was in the process of implementing a multi-threaded class library at the time but decided to take a conservative approach and use a WaitHandle for each thread. This is a less scalable solution but wasn’t really an issue as I knew that my class library would never need to use more than 8 threads concurrently.

Initial testing of the library from a COM client revealed a problem that I hadn’t anticipated: the call to the multi-threaded library method resulted in an exception being thrown with this error message:

“WaitAll for multiple handles on an STA thread is not supported”

The problem is that calling WaitAll on the thread WaitHandles from an STA thread blocks the Windows message pump and cannot be allowed otherwise the application would freeze. A quick fix for my class library was to iterate the WaitHandle array that was being passed to WaitAll and call WaitOne on each WaitHandle.

A better long term solution is to use Duffy’s single WaitHandle solution.


Written by Sea Monkey

June 15, 2009 at 8:00 am

Posted in Development

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: