public void OnTimer(object source, ElapsedEventArgs e)
 {
     if (_currentcell.HasValue)
     {
         SensorStateChangedEvent?.Invoke(1, _currentcell.Value, false);
     }
     Timer.Stop();
 }
        public bool OpenDoor(int CellNumber)
        {
            try
            {
                _currentcell = CellNumber;
                SensorStateChangedEvent?.Invoke(0, CellNumber, true);

                bool flag = false;
                for (int index1 = 0; index1 <= _cells.GetUpperBound(0); ++index1)
                {
                    for (int index2 = 0; index2 <= _cells.GetUpperBound(1); ++index2)
                    {
                        if (_cells[index1, index2] == CellNumber)
                        {
                            flag = true;
                            //start timer for auto close
                            Timer = new System.Timers.Timer {
                                Interval = 10 * 1000
                            };
                            Timer.Elapsed += OnTimer;
                            Timer.Start();

                            Thread.Sleep(500);
                        }
                    }
                }
                if (!flag)
                {
                    throw new Exception("Ячейка с номером " + CellNumber + " не найдена в конфигурации.");
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }