Guest User

Untitled

a guest
Dec 11th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. using System.Diagnostics;
  2.  
  3. public static class PerformanceManager
  4. {
  5. static PerformanceCounter cpuCounter;
  6. static PerformanceCounter ramCounter;
  7.  
  8. static PerformanceManager()
  9. {
  10. cpuCounter = new PerformanceCounter();
  11.  
  12. cpuCounter.CategoryName = "Processor";
  13. cpuCounter.CounterName = "% Processor Time";
  14. cpuCounter.InstanceName = "_Total";
  15.  
  16. ramCounter = new PerformanceCounter("Memory", "Available MBytes");
  17. }
  18.  
  19. public static string getCurrentCpuUsage()
  20. {
  21. return cpuCounter.NextValue() + "%";
  22. }
  23.  
  24. public static string getAvailableRAM()
  25. {
  26. return ramCounter.NextValue() + "MB";
  27. }
  28. }
Add Comment
Please, Sign In to add comment