started thread to wait till the other thread finishes
-
hi i have started one thread. it has read four lines. After that i want to wait that thread so that second thread so that execute. HOw can i wait a particular thread. i do not to use Thread.sleep(500); it stops all the thread. I want to wait that thread for some time or tilll other threads completed its job. thanks
-
hi i have started one thread. it has read four lines. After that i want to wait that thread so that second thread so that execute. HOw can i wait a particular thread. i do not to use Thread.sleep(500); it stops all the thread. I want to wait that thread for some time or tilll other threads completed its job. thanks
Thread.Sleep will only cause the thread on which you called it to sleep, it won't affect other threads. If you have specific places in code where you want to wait/notify, you can use the AutoResetEvent[^] class. Something like
class Test
{
AutoResetEvent evt = new AutoResetEvent(false);
void Thread1()
{
// do operation 1
evt.WaitOne();
// do operation 2
}
void Thread2()
{
// do some other operation
evt.Set(); // signal other thread to resume
// do something else
}Regards Senthil _____________________________ My Blog | My Articles | WinMacro