Link to home
Start Free TrialLog in
Avatar of mcs26
mcs26

asked on

C# Win Form STA Thread is not supported

Hi,

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,

WaitHandle.WaitAll(doneEvents);

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.

Thanks,
M
SOLUTION
Avatar of cubaman_24
cubaman_24
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mcs26
mcs26

ASKER

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?

Cheers
M
Avatar of mcs26

ASKER

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.

Cheers
M