Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Q1 -   {SingletonWatch.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(SingletonWatch.GetInstance().GetTime());
                    Thread.Sleep(250);
                }
            }
            Console.ReadKey();
        }
Exemplo n.º 2
0
 public static SingletonWatch GetInstance()
 {
     if (_instance == null)
     {
         lock (key)
         {
             if (_instance == null)
             {
                 _instance = new SingletonWatch();
             }
         }
     }
     return(_instance);
 }