MSTest crash from background threads

I have an integration test that uses multiple threads. I would like some thread to be able to skip the test (and tear the rest). However, an exception in the background thread causes an MSTest error - you just get the error message:

Agent process was stopped during test execution

I suppose I could catch some exceptions in the background thread and wake up the main thread to give a test, but is there an easier / more elegant way?

+5
source share
1 answer

( ThreadPool), Task TaskCreationOptions.LongRunning, ( ThreadPool). IsFaulted Exception . :

var task = new Task(() => { throw new InvalidOperationException(); }, TaskCreationOptions.LongRunning);
task.Start();
try { task.Wait(); }
catch { }

if (task.IsFaulted)
{
    // do something about the exception
    Console.WriteLine(task.Exception);
}
0

All Articles