Пример #1
0
 public static ColdStorage GetInstance()
 {
     if (ColdStorageRepository == null)
     {
         ColdStorageRepository = new ColdStorage();
     }
     return(ColdStorageRepository);
 }
Пример #2
0
        static void Main(string[] args)
        {
            //主线程,生产
            Truck         truck         = new Truck();
            CheeseFactory cheeseFactory = new CheeseFactory();
            ColdStorage   coldStorage   = ColdStorage.GetInstance();

            coldStorage.AddTransportEvent(truck.TransportCheese);

            while (cheeseFactory.cheeseCount < CheeseFactory.MaxCountOfCheeseFactory)
            {
                cheeseFactory.ProduceProtuction();
            }

            //线程1,运输
            ThreadStart threadStart           = new ThreadStart(truck.TransportCheese);
            Thread      threadTransportCheese = new Thread(threadStart);

            threadTransportCheese.Start();
        }
Пример #3
0
 public Truck()
 {
     coldStorage = ColdStorage.GetInstance();
 }
Пример #4
0
 public CheeseFactory()
 {
     coldStorage = ColdStorage.GetInstance();
     coldStorage.AddStartProduceEvent(ChangeProduceState);
 }