Ejemplo n.º 1
0
 public static SingletoWatch GetInstance()
 {
     if (_instance == null)
     {
         lock (key)
         {
             if (_instance == null)
             {
                 _instance = new SingletoWatch();
             }
         }
     }
     return(_instance);
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Q1 - {SingletoWatch.GetInstance().GetTime()}");
            Console.WriteLine("Press Enter 1 ");
            Console.ReadKey();

            AsyncPrinter asyncPrinter = new AsyncPrinter();
            int          index        = 1;

            for (int j = 0; j < 10; j++)
            {
                for (int i = 0; i < 10; i++)
                {
                    new Thread(asyncPrinter.CheckPrintMessage).Start();
                }
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine(index++);
                    asyncPrinter.AddMessage(SingletoWatch.GetInstance().GetTime());
                    Thread.Sleep(250);
                }
            }
            Console.ReadKey();
        }