Beispiel #1
0
        public void BtnOutPutToExcel_Click()
        {
            using (var xls = new ExcelBase())
            {
                xls.Open();
                xls.AddWorkSheet();
                int nowRowIndex = 0;
                foreach (var p in  _process)
                {
                    xls.ExlWorkSheet.Cells[++nowRowIndex, 1] = "进程:" + p.ProcessAliasName + ":" + p.MainWindowTitle + "(" + p.RemarkName + ")";

                    xls.ExlWorkSheet.Cells[nowRowIndex, 2]   = "用户总用时:" + SpyerProcess.GetMillToString(p.SumUsedTime());                   // +"ms";
                    xls.ExlWorkSheet.Cells[++nowRowIndex, 1] = "焦点时间";
                    xls.ExlWorkSheet.Cells[nowRowIndex, 2]   = "失去焦点时间";
                    xls.ExlWorkSheet.Cells[nowRowIndex, 3]   = "间隔时间";
                    foreach (var r in p)
                    {
                        xls.ExlWorkSheet.Cells[++nowRowIndex, 1] = SpyerProcess.GetMillToString(r.Begin);                       // r.Begin;
                        xls.ExlWorkSheet.Cells[nowRowIndex, 2]   = SpyerProcess.GetMillToString(r.End);
                        xls.ExlWorkSheet.Cells[nowRowIndex, 3]   = SpyerProcess.GetMillToString(r.AliveLength);
                    }
                    nowRowIndex++;
                }

                xls.SaveAs(Application.StartupPath + string.Format(@"\Inst-{0:D}.xls", DateTime.Today));
            }
        }
Beispiel #2
0
        private void _bckProcessRecord_DoWork(object sender, DoWorkEventArgs e)
        {
            do
            {
                System.Threading.Thread.Sleep(500);
                var process = SpyerProcess.GetCurrentProcessFocus();
                if (process.ProcessName == "Idle")
                {
                    continue;
                }
                var now     = new ProcessRecord(process.ProcessName, process.MainWindowTitle, process);
                var nowTime = (int)(DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds;

                if (lastRunAppName == now.ProcessAliasName)
                {
                    lastRunAppTimeRecord = Environment.TickCount;
                    if (thisAppRuntime > 0 && nowTime - thisAppRuntime > nextTipTime)
                    {
                        int    h       = nextTipTime / 3600;
                        int    m       = (nextTipTime - h * 3600) / 60;
                        int    s       = nextTipTime % 60;
                        string timeStr = "";
                        if (h > 1)
                        {
                            timeStr = string.Format("{0}小时{1}分钟", h, m);
                        }
                        else if (h == 1 || m > 9)
                        {
                            timeStr = string.Format("{0}分钟{1}秒", h * 60 + m, s);
                        }
                        else
                        {
                            timeStr = nextTipTime + "秒";
                        }
                        Program.ShowNotice(10000, "疲劳提醒", "您已经在" + now.ProcessAliasName + "上耗费了" + timeStr + "了哦", ToolTipIcon.Info, () => {
                            if (!Program.Running)
                            {
                                Program.frmMain.InfoShow_DoubleClick(this, EventArgs.Empty);
                            }
                            Program.frmMain.ui.center.apps.SetFocus(now.ProcessAliasName);                                    //用户点击时聚焦到当前
                        });
                        if (nextTipTime < 7200)
                        {
                            nextTipTime = nextTipTime * 2 + rnd.Next(250, 350);
                        }
                        else
                        {
                            nextTipTime /= 3600;
                            nextTipTime *= 3600;
                            nextTipTime += 3600;
                        }
                    }
                    continue;
                }
                var p = _process.SetBegin(now);
                if (Environment.TickCount - lastRunAppTimeRecord > 10000)              //当前的App被关闭了10秒以上方可记录
                {
                    lastRunAppName       = now.ProcessAliasName;
                    lastRunAppTimeRecord = Environment.TickCount;
                    nextTipTime          = 60;
                    thisAppRuntime       = nowTime;
                    Console.WriteLine("目标" + lastRunAppName);
                }

                //Console.WriteLine(now.ProcessName);

                _bckProcessRecord.ReportProgress(0);
            } while (!_bckProcessRecord.CancellationPending);
        }