AppInfoTool.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Azylee.Core.AppUtils
  7. {
  8. public class AppInfoTool
  9. {
  10. /// <summary>
  11. /// 读取APP Processor(可读取App的CPU使用率)
  12. /// </summary>
  13. /// <returns></returns>
  14. public static PerformanceCounter Processor()
  15. {
  16. Process p = null;
  17. PerformanceCounter processor = null;
  18. try
  19. {
  20. p = Process.GetCurrentProcess();
  21. processor = new PerformanceCounter("Process", "% Processor Time", p.ProcessName);
  22. }
  23. catch { }
  24. return processor;
  25. }
  26. /// <summary>
  27. /// 读取APP占用内存(单位:KB)
  28. /// </summary>
  29. /// <returns></returns>
  30. public static long RAM()
  31. {
  32. long value = 0;
  33. Process p = null;
  34. try
  35. {
  36. p = Process.GetCurrentProcess();
  37. value = p.WorkingSet64 / 1024;
  38. }
  39. catch { }
  40. finally { p?.Dispose(); }
  41. return value;
  42. }
  43. }
  44. }