Drowing and Delaying
I have such as a cod, it should be wait for 3second, and then drow line, and repeat all this 4 times, but it waits 12 second(3x4) and the drows 4 lines at onse. what is the problem??
//////////////////////////////////////////////////////////////////////////////////
Pen myPen = new Pen(System.Drawing.Color.Red, 1);
for (int ii = 0; ii <= 3; ii++)
{
Thread.Sleep(3000); //????? ?? 3 ???????
graphDrawingAxis.DrawLine(myPen, ii*200, 350, 200, 120);
}
/////////////////////////////////////////////////////////////////////////////
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Ryan AlfordRank #1,411 · 1.2K reputationPosted Aug 16, 2008, 2:06 PM EDT
Application.DoEvents();
AlanRank #669 · 3.6K reputationPosted Aug 17, 2008, 5:33 AM EDT
If I were you, I'd avoid the use of Thread.Sleep() in the UI thread.
Even if you can get it to work by calling Application.DoEvents(), the delay produced may not be constant because of the time taken to process pending events.
I'd use a System.Windows.Forms.Timer instead.
Arto3 reputationPosted Aug 17, 2008, 10:38 AM EDT
Muhammad Shahid Farooq107 reputationPosted Aug 17, 2008, 11:26 AM EDT