We have a legacy application with ThreadPool and WaitHandle. We wanted to write Unit-Tests using MSTest against it. We ran into a problem where by default MSTest runs in STA (Single Thread Apartment) mode and the test was throwing the following exception,
System.NotSupportedException: WaitAll for multiple handles on a STA thread is not supported. at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Int32 millisecondsTimeout, Boolean exitContext, Boolean WaitAll) at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, Int32 millisecondsTimeout, Boolean exitContext) at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, TimeSpan timeout, Boolean exitContext)
After researching for a while, we found how to change the test settings from STA to MTA.
Add a
test.runsettingsfile to you solution's folderEdit
**.Test.csprojfile and refer thetest.runsettingsfile,Now run your test, it should work.