I have web forms application. On one form I have a few functions. Which are called syncronously and takes some time. So I need to call them in different threads.
This is the sample of what I'm doing:
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";
}
If I debug (set breackpoints) lbl1.Text = "Function1 completed";
and lbl2.Text = "Function2 completed";
is getting called, but there texts are not changing on final html page.
Also Page load does not takes 5 sec.
p.s. I know asp net works different but I have no idea what I'm doing wrong.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…