Exemple #1
0
 private void Scaning(string fileName, string _params, Action <VirInfo> reCallAction, Action <ResUsageInfo> reCallAction2)
 {
     Task.Run(() =>
     {
         _isStop      = false;
         _scanProcess = new Process
         {
             StartInfo =
             {
                 Arguments = "\"" + fileName + "\"" + " -output-json" + _params,
                 FileName  = "ramecl.exe",
                 RedirectStandardOutput = true,
                 CreateNoWindow         = true,
                 WindowStyle            = ProcessWindowStyle.Hidden,
                 UseShellExecute        = false
             }
         };
         _scanProcess.Start();
         _scanProcess.BeginOutputReadLine();
         _scanProcess.OutputDataReceived += (o, args) =>
         {
             if (!string.IsNullOrEmpty(args.Data))
             {
                 var objvirInfo = new VirInfo();
                 ParseJsonResult(args.Data, ref objvirInfo);
                 if (!string.IsNullOrEmpty(objvirInfo.FileName))
                 {
                     reCallAction(objvirInfo);
                 }
             }
         };
         reCallAction2(new ResUsageInfo(-10, 0));
         while (!_isStop)
         {
             try
             {
                 if (!_scanProcess.WaitForExit(1000))
                 {
                     var objResUsageInfo = new ResUsageInfo();
                     GetCpuAndRamUsagePercent(ref objResUsageInfo);
                     reCallAction2(objResUsageInfo);
                 }
                 else
                 {
                     _isStop = true;
                 }
             }
             catch
             {
                 _isStop = true;
             }
         }
         reCallAction(new VirInfo("", "", "", true, false, "尚未处理"));
     });
 }
Exemple #2
0
        private void GetCpuAndRamUsagePercent(ref ResUsageInfo objResUsageInfo)
        {
            //calc cpu usage
            _curCpuTime = _scanProcess.TotalProcessorTime;
            objResUsageInfo.CpuUsagePercent = (_curCpuTime - _prevCpuTime).TotalMilliseconds / 10 /
                                              Environment.ProcessorCount;
            _prevCpuTime = _curCpuTime;
            //calc ram usage
            var pf = new PerformanceCounter("Process", "Working Set - Private", _scanProcess.ProcessName);

            objResUsageInfo.RamUsage = pf.NextValue() / 1048576;
        }
 private void UpdateResUsageInfoView(ResUsageInfo content)
 {
     Dispatcher.BeginInvoke(new Action(() =>
     {
         if (content.CpuUsagePercent < -8)
         {
             _currentSecond = 0;
             _dataSourceCpu.Collection.Clear();
             _dataSourceMem.Collection.Clear();
             CpuPlotter.Viewport.FitToView();
             MemPlotter.Viewport.FitToView();
         }
         else
         {
             _currentSecond++;
             double x = _currentSecond, y1 = content.CpuUsagePercent, y2 = content.RamUsage;
             _dataSourceCpu.AppendAsync(Dispatcher, new Point(x, y1));
             _dataSourceMem.AppendAsync(Dispatcher, new Point(x, y2));
         }
     }));
 }