private void connect() // Connect Device { log.Write("Trying to Connect to device ...."); if (TDecvice.Connect(deviceip, deviceport)) { this.TDecvice.devCon.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(devCon_OnAttTransactionEx); this.TDecvice.devCon.OnDisConnected += new zkemkeeper._IZKEMEvents_OnDisConnectedEventHandler(devCon_OnDisconnected); isConnected = true; CheckMachineConnectedTimer.Start(); } else { log.Write("Device Connection failed switching to retry mode...."); pingTimer = new System.Timers.Timer(30000); pingTimer.AutoReset = true; pingTimer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => { { using (Ping pinger = new Ping()) { PingReply pr = pinger.Send(deviceip); if (pr.Status == IPStatus.Success) { pingTimer.Stop(); pingTimer.Dispose(); connect(); } else { log.Write($"{deviceip} Not Rechable {DateTime.Now.ToString("dd/MM/yyyy hh:MM:ss.fff")}"); } } } }; pingTimer.Start(); } }