I'm trying to make a test for a external method to check if the method is thread safe. Multi user scenario. My code look like this.
public async Task ComputeAirPressureDropThread_OK()
{
var tasks = new List<Task<double>>();
for (int i = 1; i <= 10; i++)
{
Task<double> t = new Task<double>(() =>
{
var friterm = new Coil();
return friterm.ComputeAirPressureDrop(150);
}
);
t.Start();
tasks.Add(t);
}
var results = await Task.WhenAll(tasks);
foreach (var result in results)
{
Assert.AreEqual(result,
5.62194204005949,
0.0001);
}
}
The method ComputeAirPressureDrop(150) in the code above is what i tries to test if it is thread safe. But when running the test i get errors like this. The code is 4.6 and vs 2015. The function is a external COM dll with normal ref.
