Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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();
        }