is there a way of delaying a code statement without using threads and not a for loop
i.e is there a pre-written class/method ?
luigi
This is a discussion on delays within the C# Programming forums, part of the General Programming Boards category; is there a way of delaying a code statement without using threads and not a for loop i.e is there ...
is there a way of delaying a code statement without using threads and not a for loop
i.e is there a pre-written class/method ?
luigi
Are you talking about a blocking wait without creating another thread?
Thread.Sleep() will cause the current thread to block. If this isn't what you mean, can you be a little more specific?
Cheers![]()
yes i meant can one delay execution without creating a thread so i got
for example:
code statement;
code statement;
delay 1 second here;
code statement;
can this be done without threading, is there any classes/methods that dont require creating a thread to execute a delay routine?
yes.
This does not create another thread.Code:System.Threading.Thread.Sleep(delayInMilliseconds);
Cheers!
hi thanks TheColonial for your reply, i want simulate traffic lights changing however with the folowing code the lights still change instantaniously even with 2sec delays between method calls, can anyone explain why? im baffled![]()
the method im calling is
is it to do with the fact of being in a timer method?Code:public void OnOneSecond(Object source, EventArgs e) { label1.Text = "Simulation time " + timeIndex++ + " Seconds"; if (timeIndex%1==0) { nveh=trafficControl.CheckNTrafficSensor(); sveh=trafficControl.CheckSTrafficSensor(); stextBox.AppendText(sveh + "\r\n"); ntextBox.AppendText(nveh + "\r\n"); if(timeIndex%5==0) { switch(test) { case 0: { System.Threading.Thread.Sleep(2000); NorthLightSequence(AMBER); System.Threading.Thread.Sleep(2000); NorthLightSequence(RED); SouthLightSequence(RED_AMBER); System.Threading.Thread.Sleep(2000); SouthLightSequence(GREEN); test=1; } break; case 1: { System.Threading.Thread.Sleep(2000); NorthLightSequence(RED_AMBER); System.Threading.Thread.Sleep(2000); NorthLightSequence(GREEN); SouthLightSequence(AMBER); System.Threading.Thread.Sleep(2000); SouthLightSequence(RED); test=0; } break; }//end switch }//end if } }
Last edited by luigi40; 04-07-2005 at 10:21 AM.
Hi,
It could well be. Can you attach your .cs file to the thread so I can see how your program is set up? I should be able to help you if I can see the full code.
Cheers.
Hi TheColonial, i have totally modified the code now so that question is ir-relevant.Originally Posted by TheColonial
thanks