Is there a way to unit test WaitHandle.WaitAll()
when using Visual Studio's built-in unit testing solution. When I try and run a test that uses this function within Visual Studio the test fails and when examining the test results the following error is displayed:
WaitAll for multiple handles on a STA thread is not supported
I'd like to be able to unit test the use of WaitAll()
since an increasing amount of my API's code base is now moving to an IAsyncResult
pattern as opposed to other means of doing multi-threaded operations.
Edit
Based on Anthony's suggestion here is a simple helper method that can be used to invoke such code in a unit test environment:
public static void TestInMTAThread(ThreadStart info)
{
Thread t = new Thread(info);
t.SetApartmentState(ApartmentState.MTA);
t.Start();
t.Join();
}