Communicating between C# threads
Hi,
can someone inform me what the standard method is for
communicating between threads in C#, eg to perform synchronisation, some example code would be appreciated.
Thanks
Paul
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Yousef27 reputationPosted Apr 15, 2007, 2:07 AM EDT
example:
volatile bool bSayHello;
void MainThread()
{
// This code executes on the Main thread
while(true)
{
if(bSayHello)
{
Console.WriteLine("Hello World!");
bSayHello=false;
}
Thread.Sleep(1000);
}
}
void WorkerThread()
{
// This code executes on the worker thread
while(true)
{
// Request the main thread to Say Hello every 5 seconds.
Thread.Sleep(5000);
bSayHello=true;
}
}
The worker thread will request the main thread to type "Hello World" every 5 seconds.
Hope this helps