private void OnTimeEvent(object sender, ElapsedEventArgs e) { try { var isInUse = _klo.IsInUse(); if (!isInUse.HasValue) { notifyIcon1.Icon = new Icon("warning.ico"); notifyIcon1.Text = "Fehler"; } else if (isInUse.GetValueOrDefault(true)) { notifyIcon1.Icon = new Icon("trafficlight_red_16.ico"); notifyIcon1.Text = "Besetzt"; } else { notifyIcon1.Icon = new Icon("trafficlight_green_16.ico"); notifyIcon1.Text = "Frei"; } } finally { _timer.Enabled = true; } }
private void OnTimeEvent(object sender, ElapsedEventArgs e) { lock (this) { try { _lastState = _klo.IsInUse(); if (!_lastState.HasValue) { notifyIcon1.Icon = new Icon("warning.ico"); notifyIcon1.Text = "Fehler"; } else if (_lastState.GetValueOrDefault(true)) { notifyIcon1.Icon = new Icon("trafficlight_red_16.ico"); notifyIcon1.Text = "Besetzt seit " + Math.Round((DateTime.Now - _inUseSince).TotalMinutes, 0) + " Minuten"; } else { notifyIcon1.Icon = new Icon("trafficlight_green_16.ico"); notifyIcon1.Text = "Frei"; _inUseSince = DateTime.Now; if (_notificationWanted) { _notificationWanted = false; SendFreeNotification(); } } } finally { _timer.Enabled = true; } } }