I have a WebAPI ASP.NET solution. I have set the web.config with:
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
In a call I need to get the results of 3 tasks (10 seconds each):
Task<Cat> catAsync = GetCatAsync();
Task<Dog> dogAsync = GetDogAsync();
Task<Pig> pigAsync = GetPigAsync();
await Task.WhenAll(catAsync , dogAsync , pigAsync );
cat= catAsync.Result;
dog= dogAsync.Result;
pig= pigAsync.Result;
I can call it once, but subsequent calls to this seem to just die in a thread, Cat and Dog may run but Pig seems to vaporize. A minute or so later these start appearing:
The thread '<No Name>' (0x2f60) has exited with code 0 (0x0).
The thread '<No Name>' (0x974) has exited with code 0 (0x0).
The thread '<No Name>' (0x1ea8) has exited with code 0 (0x0).
My Tasks look like this:
private async Task<Cat> CatAsync()
{
await Task.Run(() =>
{
//Use WCF to get some data from a service
});
return cat;
}
Running IISRESET let's me run the site again once.
* EDIT
I posted the solution below that works with this example after reading the answer by Panagiotis Kanavos