示例#1
0
 public SingleTone GetInstanceLazy()
 {
     if (instance == null)
     {
         instance = new SingleTone();
     }
     return(instance);
 }
示例#2
0
 public SingleTone GetInstanceThreadSafe()
 {
     Contract.Ensures(Contract.Result <SingleTone>() != null);
     lock (lockThis)
     {
         if (instance == null)
         {
             instance = new SingleTone();
         }
         return(instance);
     }
 }
示例#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());
            }
        }
示例#4
0
 public SingleTone GetInstanceEager()
 {
     instance = new SingleTone();
     return(instance);
 }