private void ChildItem_CheckStateChanged(object sender, EventArgs e) { ToolStripItem menuItem = (ToolStripItem)sender; SingleTimerLib.SingleTimer _t = TimersList[menuItem.Text.SubStringByIndexOf("-[").Trim()]; Color _fc = Color.Black; Color _bc = Color.White; if (_t != null) { if (_t.TimerIsRunning) { _fc = Color.NavajoWhite; _bc = Color.LightSeaGreen; _t.StopTimer(); DebugPrint(string.Format("{0}: {1} is no longer running!", "ChildItem_CheckStateChanged", _t.Name)); } else { _t.StartTimer(); DebugPrint(string.Format("{0}: {1} is now running!", "ChildItem_CheckStateChanged", _t.Name)); } menuItem.BackColor = _t.TimerIsRunning ? Color.LightSeaGreen : Color.LightPink; menuItem.ForeColor = _t.TimerIsRunning ? Color.NavajoWhite : Color.MintCream; Rows[_t.RowIndex].Cells[1].Style.BackColor = menuItem.BackColor; Rows[_t.RowIndex].Cells[1].Style.ForeColor = menuItem.ForeColor; } else { menuItem.BackColor = SystemColors.InactiveCaption; menuItem.ForeColor = SystemColors.InactiveCaptionText; } }
private void DoClose() { _isClosing = true; Properties.Settings.Default.Save(); List <string> listOfKeys = new List <string>(); foreach (string _k in TimersList.Keys) { listOfKeys.Add(_k); } foreach (string name in listOfKeys) { SingleTimerLib.SingleTimer _t = TimersList[name]; _t.PropertyChanged -= SingleTimer_PropertyChanged; _t.SingleTimerChanged -= SingleTimer_SingleTimerChanged; _t.TimerReset -= SingleTimer_OnTimerReset; _t.StopTimer(); TimersList.Remove(_t.CanonicalName); TimerName2RowIndexDictionary.Remove(_t.CanonicalName); DebugPrint(string.Format("Timer {0} is being is about to be disposed!", _t.Name)); _t.Dispose(); } WriteDataToXml(); listOfKeys.Clear(); listOfKeys = null; Hide(); jobTimersIcon.Visible = false; FormClosing -= JobTimerForm_FormClosing; Close(); Application.Exit(); }
private void TreadSafeDeleteDataGridViewRows() { if (timersDataGridView.InvokeRequired) { timersDataGridView.Invoke(new Action(TreadSafeDeleteDataGridViewRows)); return; } foreach (DataGridViewRow _dr in timersDataGridView.SelectedRows) { string name = timersDataGridView.CurrentRow.TimerCanonicalName(); SingleTimerLib.SingleTimer _t = TimersList[name]; _t.SingleTimerChanged -= SingleTimer_SingleTimerChanged; _t.PropertyChanged -= SingleTimer_PropertyChanged; _t.TimerReset -= SingleTimer_OnTimerReset; _t.StopTimer(); Debug.Assert(_t.CanonicalName == Timers.Rows[_t.RowIndex].TimerCanonicalName()); Timers.Rows.RemoveAt(_t.RowIndex); Timers.AcceptChanges(); ThreadSafeUpdateDataGridView(); TimerName2RowIndexDictionary.Remove(name); TimersList.Remove(name); _t.Dispose(); } }