首先,我要提前道歉:我无法将以下错误隔离为简单的控制台应用程序。然而,在我的相对简单的ASP.NET Web Forms应用程序中,以下代码将导致当前线程无限期地阻塞:
任务状态仅保持为'WaitingForActivation'。有人知道为什么会这样吗?
public class MyModule : IHttpModule
{
public void Dispose()
{
}
public void Init(System.Web.HttpApplication context)
{
context.BeginRequest += this.Context_BeginRequest;
}
private void Context_BeginRequest(object sender, EventArgs e)
{
Sleep().Wait();
var x = 2; // This line is never hit.
}
private async Task Sleep()
{
await TaskEx.Run(() => System.Threading.Thread.Sleep(1000));
}
}
任务状态仅保持为'WaitingForActivation'。有人知道为什么会这样吗?