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)