/// <summary> If the user hasn't moved in a while, start the sleep dialog. </summary> private void HandleTimerTick(object sender, EventArgs e) { if (InputData.TimeSinceLastInput < _limit) { // if the user moves the mouse, then hide the dialog _sleepDialog?.Close(); } else { // it's currently taken care of if (_sleepDialog != null) { return; } // pop up a warning and let the user handle the problem _sleepDialog = new SleepWarningDialog(); _sleepDialog.Closed += delegate { _sleepDialog.Dispose(); _sleepDialog = null; }; _sleepDialog.Show(); } }
/// <summary> Default constructor. </summary> public ApplicationDialog() { InitializeComponent(); var menu = new ContextMenu(); menu.MenuItems.Add(new MenuItem("Sleep Now", (s, a) => SleepWarningDialog.PutComputerToSleep())); menu.MenuItems.Add("-"); menu.MenuItems.Add(_enabledMenuItem = new MenuItem("Enabled", HandleEnabledChanged)); menu.MenuItems.Add(new MenuItem("Exit", ((sender, args) => Close()))); components.Add(new NotifyIcon { Icon = this.Icon, Visible = true, ContextMenu = menu, Text = "Put the computer to sleep after the user is Idle", }); tmrCheckTimer.Interval = (int)_timerTick.TotalMilliseconds; HandleEnabledChanged(); }