Pradeep S

Pradeep S

  • 1.5k
  • 387
  • 190.6k

How to update UI controls from another thread in ASP.NET?

Sep 29 2019 10:43 PM
How to update UI controls(ex. list box) from another thread in ASP.NET? From the below code I am expecting to update listbox once performLongTask1() and performLongTask2() completes execution and also should update in the order of finishing task.
  1. protected void Button1_Click(object sender, EventArgs e)    
  2. {    
  3.             Thread t1 = new Thread(performLongTask1);    
  4.             Thread t2 = new Thread(performLongTask2);    
  5.             t1.Start();    
  6.             t2.Start();    
  7.             ListBox1.Items.Add("LongTask1 Started");    
  8.             ListBox1.Items.Add("LongTask2 Started");    
  9. }    
  10. private  void performLongTask1()    
  11. {              
  12.             Thread.Sleep(5000);    
  13.            //ListBox1.Items.Add("LongTask1 Completed");    
  14. }    
  15. private  void performLongTask2()    
  16. {    
  17.            Thread.Sleep(10000);              
  18.            //ListBox1.Items.Add("LongTask2 Completed");    
  19. }  

Answers (3)