private static void LoadProgramTimes() { StringCollection programSettings = Settings.Default.ProgramTrackData; if (programSettings == null) { return; } foreach (string str in programSettings) { string[] arr = str.Split('?'); string[] details = arr[1].Split('`'); if (details.Length != 4) { continue; } ProcessTime pt = new ProcessTime(details[0], details[1], ulong.Parse(details[2])); pt.SetTracked(bool.Parse(details[3])); if (pt.GetTime() == 0) { continue; } savedProcessTime.Add(arr[0], pt); } }
public void NewProcessAdded(ProcessTime pt) { if (InvokeRequired) { Invoke(new Action(() => { if (this.IsDisposed) { return; } NewProcessAdded(pt); })); return; } if (trackedProcessList.ContainsKey(pt.ProcessName)) { return; } ProcessTracked tracked = new ProcessTracked(); tracked.ProcessName = pt.ProcessName; tracked.ProcessTitle = pt.ProcessTitle; tracked.Timestamp = pt.GetTimeFormatted(); tracked.SetChecked(pt.GetTracked()); trackedProcessList.Add(pt.ProcessName, tracked); trackerList.Controls.Add(tracked); }
public void UpdateTimestamp(ProcessTime pt) { if (IsDisposed) { return; } if (InvokeRequired) { Invoke(new Action(() => { if (this.IsDisposed) { return; } UpdateTimestamp(pt); })); return; } if (!trackedProcessList.ContainsKey(pt.ProcessName)) { NewProcessAdded(pt); } else { trackedProcessList[pt.ProcessName].Timestamp = pt.GetTimeFormatted(); } }
public MainForm() { InitializeComponent(); foreach (string key in Program.processTimes.Keys) { ProcessTime pt = Program.processTimes[key]; NewProcessAdded(pt); } foreach (string key in Program.savedProcessTime.Keys) { ProcessTime pt = Program.savedProcessTime[key]; NewProcessAdded(pt); } }
private static void FindProcessLoop() { Program.findProcessTimer = new System.Timers.Timer(2000); findProcessTimer.Elapsed += (o, o2) => { findProcessTimer.Interval = secondsPerLoop * 1000; Process[] processes = Process.GetProcesses(); foreach (Process p in processes) { if (processTimes.ContainsKey(p.ProcessName) || string.IsNullOrEmpty(p.MainWindowTitle)) { continue; } else { try { p.EnableRaisingEvents = true; if (savedProcessTime.ContainsKey(p.ProcessName)) { ProcessTime pt = savedProcessTime[p.ProcessName]; ProcessTime newPT = new ProcessTime(p.ProcessName, p.MainWindowTitle, pt.GetTime()); newPT.SetTracked(pt.GetTracked()); processTimes.Add(p.ProcessName, newPT); if (mainForm != null && mainForm.Visible) { mainForm.NewProcessAdded(pt); } } else { processTimes.Add(p.ProcessName, new ProcessTime(p.ProcessName, p.MainWindowTitle)); if (mainForm != null && mainForm.Visible) { mainForm.NewProcessAdded(processTimes[p.ProcessName]); } } p.Exited += Process_Exited; } catch (Win32Exception) { } } } }; Program.findProcessTimer.AutoReset = true; Program.findProcessTimer.Start(); }
public void ProcessClosed(ProcessTime pt) { /*if (InvokeRequired) * { * Invoke(new Action(() => { * if (this.IsDisposed) return; * ProcessClosed(pt); * })); * return; * } * if(trackedProcessList.ContainsKey(pt.ProcessName)) * { * trackerList.Controls.Remove(trackedProcessList[pt.ProcessName]); * trackedProcessList[pt.ProcessName].Dispose(); * trackedProcessList.Remove(pt.ProcessName); * }*/ }
private static void SaveProgramTimes() { Debug.WriteLine("Saving data"); StringCollection collection = new StringCollection(); List <string> addedKeys = new List <string>(); foreach (string key in processTimes.Keys) { if (addedKeys.Contains(key)) { continue; } ProcessTime pt = processTimes[key]; if (pt.GetTime() == 0) { continue; } collection.Add($"{key}?{pt.ProcessName}`{pt.ProcessTitle}`{pt.GetTime()}`{pt.GetTracked()}"); addedKeys.Add(key); } foreach (string key in savedProcessTime.Keys) { if (addedKeys.Contains(key)) { continue; } ProcessTime pt = savedProcessTime[key]; if (pt.GetTime() == 0) { continue; } collection.Add($"{key}?{pt.ProcessName}`{pt.ProcessTitle}`{pt.GetTime()}`{pt.GetTracked()}"); addedKeys.Add(key); } Settings.Default.ProgramTrackData = collection; Settings.Default.Save(); }