我有一个.net 4.0多层网络应用。我有一个很长的进程正在运行,我只需要更新用户作为记录进程...只使用一个简单的消息到屏幕。
在业务逻辑中,我有一些异步调用正在进行中。如果我真的单步执行代码,它似乎做了它需要做的事情......在它遇到漫长的过程之后,似乎会产生一个新的线程来更新前端。在UI中,我在更新面板中有一个文字和运行它的代码:
FileApplicationTests fileApplicationPageTest = new FileApplicationTests();
fileApplicationPageTest.OnReadyToBeDisplayed += new DisplayMessageEventHandler(WriteToLog);
private void WriteToLog(object sender, string log_entry)
{
Literal1.Text += log_entry + "<br/>";
}
正如我所说,我可以逐步完成这一切,但一切看起来都很好......但网页本身直到最后才会更新。
这是中间层......
public delegate void DisplayMessageEventHandler(object sender, string msg);
public class FileApplicationTests
{
public event DisplayMessageEventHandler OnReadyToBeDisplayed;
public string FileApplication()
{
string msg = string.Empty;
FileApplicationFrameWork filer = new FileApplicationFrameWork();
filer.OnRecordProcessed += new ProcessedEventHandler(PrintMsg);
filer.FileApplicationWithoutRegistering();
return msg;
}
private void PrintMsg(object sender, string msg)
{
OnReadyToBeDisplayed(this, msg);
}
}
}
和用户界面:
FileApplicationTests fileApplicationPageTest = new FileApplicationTests();
fileApplicationPageTest.OnReadyToBeDisplayed += new DisplayMessageEventHandler(WriteToLog);
fileApplicationPageTest.FileApplication();
private void WriteToLog(object sender, string log_entry)
{
Literal1.Text += log_entry + "<br/>";
}