我有一个执行长时间处理的页面(在某处写一些pdf),所以我有以下内容:
我的 ArchiveDoc.aspx 页面:(该页面在页面指令中有一个标签(称为进度)和 Async="true")
delegate void archiveFuncDelegate(int idTurnover, string serverMapPath);
delegate void UpdateUIDelegate(string Text);
protected void Page_Load(object sender, EventArgs e)
{
Page.AddOnPreRenderCompleteAsync(BeginTask, EndTask);
this.progress.Text = "0";
}
private void UpdateUI(string Text)
{
this.progress.Text = Text;
}
private IAsyncResult BeginTask(object sender, EventArgs e, AsyncCallback cb, object state)
{
// invoke
archiveFuncDelegate del = asyncArchivageFacture;
IAsyncResult result = del.BeginInvoke(cb,null);
return result;
}
private void EndTask(IAsyncResult ar)
{
if (!ar.IsCompleted)
{
progress.Text = "Error";
}
else
{
progress.Text = "OK";
}
}
#region Archive (thread)
// long processing task (exemple)
public void asyncArchivageFacture()
{
// exemple
int total = 101;
int progress = 0;
for(int i=0; i<total; i++)
{
progress = i*100 / total;
updateUi.Invoke(progress + "%");
Thread.Sleep(2000);
}
}
#endregion
当我调用我的页面时,线程被调用(asyncArchivageFacture()以及UpdateUI()),但网页永远不会更新:我在浏览器中获得了带有空白页面的加载符号,一旦线程完成,页面最终显示“OK”。它不显示进度(10%.. 20%..)
知道有什么问题吗?谢谢!