public void HandleMachineStatus(string machineName, MachineStatus machineStatus) { lock (_locker) { if (machineStatus == MachineStatus.manual) { //starts a handler if not exists if (!this._handlersList.ContainsKey(machineName)) { MachineStopHandler handler = new MachineStopHandler(machineName); handler.StartWatching(); handler.MachineStopped += new MachineStopped(handler_MachineStopped); this._handlersList.Add(machineName, handler); } } else if (machineStatus == MachineStatus.automatic) { //removes a hander if exists because machine resume operation if (this._handlersList.ContainsKey(machineName)) { MachineStopHandler handler = this._handlersList[machineName]; handler.StopWatching(); handler.MachineStopped -= handler_MachineStopped; handler.Dispose(); this._handlersList.Remove(machineName); if (MachineHasResumedOperation != null) { MachineHasResumedOperation(machineName); } } } } }
public void handler_MachineStopped(MachineStopHandler sender) { if (MachineIsStopped != null) { MachineIsStopped(sender.MAchineName); //removes the handler lock (_locker) { this._handlersList.Remove(sender.MAchineName); sender.Dispose(); } } }