c# - Windows Form App for loop not working -
int = 0; private void button1_click(object sender, eventargs e) { (int j = 10; j < 1000; j = j + 1) { string y = i.tostring(); webbrowser1.document.getelementbyid("lst-ib").setattribute("value", y); i++; } }
this section of code i'm working in windows form application want input value , show going jumps end , puts last output instead of counting up. people said use timers haven't been able them work. ideas?
you're locking ui thread loop, doesn't update control until it's done work. end seeing final value, when loop complete , ui refreshes.
take @ using timer
control instead. can tell raise event @ regular intervals, , it'll allow ui updated correctly.
add timer
form
, insert following code constructor try out. currently, updates element every 1 ms (in reality, won't fast).
int = 0; int j = 10; timer1.interval = 1; timer1.tick += (s, e) => { string y = i.tostring(); webbrowser1.document.getelementbyid("lst-ib").setattribute("value", y); i++; j++; if (j > 1000) timer1.stop(); }; timer1.start();
Comments
Post a Comment