我有一份报告大约需要 2 或 3 分钟才能提取所有数据
所以我试图使用 ASP.net 异步页面来防止超时。但无法让它工作
这就是我正在做的事情:
private delegate List<PublishedPagesDataItem> AsyncReportDataDelegate();
private AsyncReportDataDelegate longRunningMethod;
private List<PublishedPagesDataItem> reportData;
public PublishedPagesReport() // this is the constructor
{
reportData = new List<PublishedPagesDataItem>();
longRunningMethod = GetReportData;
}
protected void Page_Load(object sender, EventArgs e)
{
this.PreRenderComplete +=
new EventHandler(Page_PreRenderComplete);
AddOnPreRenderCompleteAsync(
new BeginEventHandler(BeginAsynchOperation),
new EndEventHandler(EndAsynchOperation)
);
}
private List<PublishedPagesDataItem> GetReportData()
{
// this is a long running method
}
private IAsyncResult BeginAsynchOperation(object sender, EventArgs e, AsyncCallback cb, object extradata)
{
return longRunningMethod.BeginInvoke(cb, extradata);
}
private void EndAsynchOperation(IAsyncResult ar)
{
reportData = longRunningMethod.EndInvoke(ar);
}
private void Page_PreRenderComplete(object sender, EventArgs e)
{
reportGridView.DataSource = reportData;
reportGridView.DataBind();
}
所以我有一个代表长期运行方法(GetReportData)的委托。
我试图按照这篇文章来称呼它:
http://msdn.microsoft.com/en-us/magazine/cc163725.aspx
长时间运行的方法确实在调试器中完成,但 EndAsynchOperation 和 Page_PreRenderComplete 方法上的断点永远不会被命中
知道我做错了什么吗?