c# - For loop bug in label -


well, simple, creat window form, put in button , label, , give button click event.

    private void button1_click(object sender, eventargs e)     {         int xa;         int ya;         (xa = 647; xa < 982; xa++)              (ya = 262; ya < 598; ya++)             {                 label1.text = xa.tostring() + " " + ya.tostring();             }     } 

and program stuck 20 seconds when click button. how can fix this?

you've got off of ui thread. try this:

private void button1_click(object sender, eventargs e) {     threadpool.queueuserworkitem(p => doit());             }  private void doit() {     int xa;     int ya;     (xa = 647; xa < 982; xa++)          (ya = 262; ya < 598; ya++)         {             this.invoke(new action(() => { label1.text = xa.tostring() + " " + ya.tostring(); }));         } } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -