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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -