【发布时间】:2011-10-18 08:25:04
【问题描述】:
首先向前道歉:我无法将以下错误隔离到一个简单的控制台应用程序中。但是,在我比较简单的 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”。有谁知道为什么会这样?
【问题讨论】:
-
在控制台 exe 中运行良好;好像和asp.net有关
标签: c# .net asp.net task-parallel-library async-ctp