使用异步页面的 Asp.net 长时间运行进程
我有一份报告,需要大约 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 方法上的断点永远不会被击中,
知道我做错了什么吗?
I have a report that takes about 2 or 3 minutes to pull all the data
So I am trying to use ASP.net Asynch pages to prevent a timeout. But can't get it to work
Here's what I am doing :
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();
}
So I have a delegate representing the Long running method (GetReportData).
And I am trying to call it as per this article :
http://msdn.microsoft.com/en-us/magazine/cc163725.aspx
The long running method does complete in the debugger but breakpoints on the EndAsynchOperation and Page_PreRenderComplete methods never get hit
any idea what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的代码有效。不知道有什么区别,除了有一个
if (!IsPostBack)
无论如何,现在解决了
the code below works. not sure what the difference is, except that there is a
if (!IsPostBack)
anyway, now solved