Another Thread Synchronization in C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace AnotherThreadSynchronization { class Program { static object baton = new object(); static Random rmd = new Random(); static void Main(string[] args) { for (int i = 0; i < 6; i++) { new Thread(AnotherThread) .Start(); } } static void AnotherThread() { Console.WriteLine(Thread.CurrentThread.ManagedThreadId + "- First cell"); lock(baton) { Console.WriteLine(Thread.CurrentThread.ManagedThreadId + "- Second cell"); Thread.Sleep(rmd.Next(2000)); Console.WriteLine(Thread.CurrentThread.ManagedThreadId + "- Third cell"); } Console.WriteLine(Thread.CurrentThread.ManagedThreadId + "- Forth cell"); } } }