using System;
using System.Threading;
class Thread_Sync
{
public void PrintNumbers()
{
lock (this)
{
for (int i = 1; i <= 10; i++)
{
Console.WriteLine(i);
Thread.Sleep(500);
}
}
}
static void Main(string[] args)
{
Thread_Sync t = new Thread_Sync();
Thread t1 = new Thread(t.PrintNumbers);
Thread t2 = new Thread(t.PrintNumbers);
t1.Start();
t2.Start();
}
}This code snippet is a example of thread synchronization in C# .Net.
