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 instance = ChocolateBoiler.GetInstance("First Instance"); Console.WriteLine(instance.GetName()); instance = ChocolateBoiler.GetInstance("Second Instance"); Console.WriteLine(instance.GetName()); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var factory = ChocolateBoiler.GetInstance(); var factory2 = ChocolateBoiler.GetInstance(); factory.Boil(); factory.Drain(); factory.Fill(); }
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()); }