static void Main(string[] args) { ChocolateBoiler chocolateBoiler = ChocolateBoiler.GetInstance(); ChocolateBoiler chocolateBoiler2 = ChocolateBoiler.GetInstance(); Console.WriteLine("ChocolateBoiler:" + chocolateBoiler); Console.WriteLine("ChocolateBoiler2:" + chocolateBoiler2); chocolateBoiler.Fill(); Console.WriteLine("\nFILL:"); Console.WriteLine("ChocolateBoiler:" + chocolateBoiler); Console.WriteLine("ChocolateBoiler2:" + chocolateBoiler2); chocolateBoiler2.Boil(); Console.WriteLine("\nBOIL:"); Console.WriteLine("ChocolateBoiler:" + chocolateBoiler); Console.WriteLine("ChocolateBoiler2:" + chocolateBoiler2); chocolateBoiler.Drain(); Console.WriteLine("\nDRAIN:"); Console.WriteLine("ChocolateBoiler:" + chocolateBoiler); Console.WriteLine("ChocolateBoiler2:" + chocolateBoiler2); }
static void Main(string[] args) { ChocolateBoiler test = ChocolateBoiler.GetBoiler(); test.Fill(); Task.Run(() => test.Boil()); Thread.Sleep(2000); test.Boil(); Console.WriteLine(); }
static void Main(string[] args) { ChocolateBoiler boiler = ChocolateBoiler.GetInstance(); var tasks = new List <Task>(); for (int i = 0; i < 50; i++) { tasks.Add(Task.Factory.StartNew(() => boiler.Fill())); tasks.Add(Task.Factory.StartNew(() => boiler.Drain())); tasks.Add(Task.Factory.StartNew(() => boiler.Boil())); } Task.WaitAll(tasks.ToArray()); }