首先是一个向前的道歉:我无法将以下错误隔离到一个简单的控制台应用程序中。但是,在我比较简单的 ASP.NET Web Forms 应用程序中,下面的代码会导致当前线程无限期阻塞:
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”。有谁知道为什么会发生这种情况?