C# Win Form STA Thread is not supported

Posted on 2012-03-12
Last Modified: 2012-06-22

I had a class I used that use's multiple threads. I have since added this class to a new windows from project. The code complies however at the line below,


Open in new window

an NotSupportedException was unhandlewed is thrown. The error message is "WaitAll for multiple handles on a STA thread is not supported".

After reading some webpages on google, what I understand is that a window form run in single thread so cannot use multi threading without changing the attribute to MTA. Is this correct and how do I do such a thing? Also is this the same for WPF forms as I'm looking to learn about them very soon.

Question by:mcs26
  • 2

Assisted Solution

cubaman_24 earned 250 total points
ID: 37710422
You can set the threaded apartment in Main method as an attribute. See this:
And this:

Best regards.
LVL 85

Accepted Solution

Mike Tomlinson earned 250 total points
ID: 37710428
Couldn't you just iterate over them and call WaitOne() against each one?
            foreach (WaitHandle doneEvent in doneEvents)

Open in new window


Author Comment

ID: 37710444
Hi cubaman,

Thanks for the reply. Sorry those link's don't make a huge amount of sense to me. Am I able to change the attribute of a windows form & WPF to MTA from STA and make use of multithreading?


Author Comment

ID: 37710452
Hi idle_mind,

Thanks for the reply. I think I have seen this as a viable soultion but wanted to know if I could change the attribute of either a windows form or WPF form to enable me to use to  WaitHandle.WaitAll method.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now