I assume this is a simple question for you. Here we go:
On my .aspx page, I have a label Label1 and a button Button1 surrounded by an Update Panel.
A click on the Button invokes the code-behind method that looks as follows:
protected void Click(object sender, EventArgs e) {
ThreadProc("Hello");
Thread.Sleep(2000);
ThreadProc("Hello2");
Thread.Sleep(2000);
ThreadProc("Hello3");
}
void ThreadProc(string info) {
Label1.Text = info;
// UpdatePanel1.Update();
}
What I would like to see is that the Label is updated and displayed (rendered) according to what the code does. So it should Hello, Hello2 for 2 seconds and finally Hello3 should be displayed.
It appears that only the last Hello3 is rendered. Can someone explain why this happens and how I can implement my idea?
The overall task I try to accomplish is that a click on the button calls a multithreaded function that queries different pages. Whenever a worker thread returns from his mission, it is supposed to update a gridview with the newly added record. Here, the issue is the same: only after all threads have done their job, the webpart is updated.
Thanks a lot for any help!
Cheers
Christoph
Because the code is running on the web server, it processes the entire method
Click()before rendering the final page and sending it to the client’s web browser. Therefore, you only see the final results, which has “Hello3” as theLabel1.Text.The effect that Thread.Sleep(2000) has on your code is that the HTTP response from the web server takes 4.x seconds instead of only a fraction of a second if you left it out.
However, if you want to see each update to the
Label1.Text, you can do that with an asynchronous AJAX call.