How can i make my program to loop for .5 second before moving on to next line of code. Is it the same as using Thread.Sleep(500) Yes, it's running on a thread but i don't know doing that how it's gonna affect other threads.
If you say Thread.Sleep(500),then this results in your thread being suspended while a context switch happens.Other threads may be able to freely go beyond this line of code and execute.Can you give us the scenario
i have 2 threads. the main one is where my app is running and the second one is constantly reading data from a target. So when i send a handshake to the target i need to wait for .5 s for it to response and capture that data.
wait time
chen55347
Alberto Borbolla MVP
MSDN Forum User
Thread.Sleep puts the currently executing thread to sleep. Say you have thread 1 (main thread) and Thread 2(target reading thread)
{
//In Main
Thread t2 = new Thread(new ThreadStart(this.PollTraget));
t2.Start();
//Main thread is running doing its work
}
void PollTraget()
{
//Here t2 executes, polling target repeatedly
//Send handshake
Thread.Sleep(5000);//Casues t2 to sleep and possible context switch to main thread
//t2 becomes runnable
}
Hope this answers your question.
Jackie8640