public static ColdStorage GetInstance() { if (ColdStorageRepository == null) { ColdStorageRepository = new ColdStorage(); } return(ColdStorageRepository); }
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(); }
public Truck() { coldStorage = ColdStorage.GetInstance(); }
public CheeseFactory() { coldStorage = ColdStorage.GetInstance(); coldStorage.AddStartProduceEvent(ChangeProduceState); }