I have a winform with a textbox and a button.
I have a loop that is supposed to write numbers into the text box.
When I run the program (hit the button), no numbers are being written to the textbox until the 10 seconds elapse, reaching the end of the loop, when it writes 99.
What is wrong in this seemingly simple function? I probably overlook something!?
Thanks!
int index;
private void button2_Click(object sender, EventArgs e)
{
for (index = 0; index < 100; index++)
{
textboxOut.Text = index.ToString();
Thread.Sleep(100);
}
}
VulpesPosted Oct 31, 2014, 6:41 PM
RahulPosted Oct 31, 2014, 5:24 PM
http://www.c-sharpcorner.com/UploadFile/mahesh/C-Sharp-timer/
SamPosted Oct 31, 2014, 4:36 PM
I believe I have 100 iterations and 100 mSec delay, which yields 100 X 0.1 = 10 sec.
And in fact, it waits 10 Sec before displaying 99. (but nothing displayed before)
I still have no idea why this does not work. It is as simple as 123...
RahulPosted Oct 31, 2014, 11:57 AM
Thread.Sleep(10000);
now it will wait for 10 sec