我有网络表单应用程序.在一种形式上,我有一些功能.这被称为同步并需要一些时间.所以我需要在不同的线程中调用它们.
这是我正在做的样本:
protected void Page_Load(object sender, EventArgs e)
{
Thread t1 = new Thread(new ThreadStart(Function1));
t1.Start();
Thread t2 = new Thread(new ThreadStart(Function2));
t2.Start();
}
private void Function1()
{
Thread.Sleep(5000);
lbl1.Text = "Function1 completed";
}
private void Function2()
{
Thread.Sleep(5000);
lbl2.Text = "Function2 completed";
}
Run Code Online (Sandbox Code Playgroud)
如果我调试(设置breackpoints)lbl1.Text = "Function1 completed";并被lbl2.Text = "Function2 completed";调用,但最终的html页面上的文本没有变化.
页面加载也不需要5秒.
ps我知道asp网络有所不同,但我不知道我做错了什么.