c# - Update GUI components from Begininvoke -


so have basic windows application want count 1 10000 , show numbers in label:

private void button1_click(object sender, eventargs e)     {         thread thread = new thread(() =>         {             (int = 0; < 10000; i++)             {                 begininvoke((methodinvoker)delegate ()                 {                     label3.text = i.tostring();                 });             }         });          thread.start();  } 

the problem label text doesn't update , shows last loop counter i.e. 9999. begininvoke called on ui thread? why not label updated correctly?

thanks.

because begininvoke asynchronous call, you're sending many updates text box update fast enough, time text box has got around drawing, it's counted 10000!

you can synchronously update text, is, calling loop halt until text box has updated , finished, use invoke instead of begininvoke.


Comments

Popular posts from this blog

javascript - Why Selenium can't find an element that is graphically visible -

java - How to compare two classes -

mysql - Gateway Timeout Error on Insert 70000 record using Hibernate in Java -