We have an IIS website running C# code which is compiled by IIS (this is not running from a *.cs file, it's within code with <% %>
tags on a aspx page. There are no async
directives used in the page code. We have a .NET library with a class that exposes async methods. When we try to call the async method synchronously, like this:
var articles = _cmsClient.GetAllArticlesAsync().Result;
the page hangs indefinitley. The solution we found by trial and error is to wrap the async call in a task:
List<Article> articles = null;
var wpLoadTask = Task.Run(async () =>
{
articles = await _cmsClient.GetAllArticlesAsync();
});
wpLoadTask.Wait();
This is working but I'm curious to understand why.