public bool AddWorkableUnitToQueue(Type model, string name, Coordinates coordinatesStatio, Coordinates coordinatesWork) { bool result = false; IWorkingUnit workingUnit = Activator.CreateInstance(model) as IWorkingUnit; workingUnit.ParkingPos = coordinatesStatio; workingUnit.WorkingPos = coordinatesWork; Thread th = new Thread(() => { lock (lockObj) { if (QueueFreeSlots == 0 && StorageFreeSlots == 0) { result = false; } else { FactoryQueueElement element = new FactoryQueueElement(model, name, coordinatesStatio, coordinatesWork); Queue.Enqueue(element); Thread.Sleep(TimeSpan.FromSeconds(workingUnit.BuildTime)); QueueTime += TimeSpan.FromSeconds(workingUnit.BuildTime); if (StorageFreeSlots > 0) { Queue.Dequeue(); IBaseUnit baseUnit = (IBaseUnit)workingUnit; baseUnit.Move(coordinatesStatio, coordinatesWork); Storage.Add(Activator.CreateInstance(model) as ITestingUnit); } result = true; } } }); th.Start(); return(result); }