Esempio n. 1
0
 public SingleTone GetInstanceLazy()
 {
     if (instance == null)
     {
         instance = new SingleTone();
     }
     return(instance);
 }
Esempio n. 2
0
 public SingleTone GetInstanceThreadSafe()
 {
     Contract.Ensures(Contract.Result <SingleTone>() != null);
     lock (lockThis)
     {
         if (instance == null)
         {
             instance = new SingleTone();
         }
         return(instance);
     }
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                var myObject = new SingleTone().GetInstanceEager();
                Console.WriteLine(myObject.time.ToString());
            }
            for (int i = 0; i < 10; i++)
            {
                var myObject = new SingleTone().GetInstanceEager();
                Console.WriteLine(myObject.time.ToString());
            }

            for (int i = 0; i < 10; i++)
            {
                var myObject = new SingleTone().GetInstanceThreadSafe();
                Console.WriteLine(myObject.time.ToString());
            }
        }
Esempio n. 4
0
 public SingleTone GetInstanceEager()
 {
     instance = new SingleTone();
     return(instance);
 }