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
Post a Comment