AppInfoTool.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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占用CPU
  12. /// </summary>
  13. /// <returns></returns>
  14. public static double CPU()
  15. {
  16. double value = 0;
  17. Process p = null;
  18. PerformanceCounter processor = null;
  19. try
  20. {
  21. p = Process.GetCurrentProcess();
  22. processor = new PerformanceCounter("Process", "% Processor Time", p.ProcessName);
  23. value = processor.NextValue();
  24. }
  25. catch { }
  26. finally
  27. {
  28. processor?.Dispose();
  29. p?.Dispose();
  30. }
  31. return value;
  32. }
  33. /// <summary>
  34. /// 读取APP占用内存
  35. /// </summary>
  36. /// <returns></returns>
  37. public static long RAM()
  38. {
  39. long value = 0;
  40. Process p = null;
  41. try
  42. {
  43. p = Process.GetCurrentProcess();
  44. value = p.WorkingSet64;
  45. }
  46. catch { }
  47. finally { p?.Dispose(); }
  48. return value;
  49. }
  50. }
  51. }