Advertisement
Guest User

Ma Codes

a guest
Mar 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7. using System.Threading;
  8. using System.Speech.Synthesis;
  9.  
  10. namespace Jarvis
  11.  
  12. {
  13. class Program
  14. {
  15. /// <summary>
  16. /// Where The program Starts
  17. /// </summary>
  18. /// <param name="args"></param>
  19. static void Main(string[] args)
  20. {
  21. #region My Performance Counters
  22. //This will pull the current CPU usage
  23. PerformanceCounter perfCpuCount = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");
  24.  
  25. //This will pull the current available Memory in Megabytes
  26. PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes");
  27.  
  28. //This will Pull the System Uptime (In Seconds)
  29. PerformanceCounter perfUptimeCount = new PerformanceCounter("System", "System Up Time");
  30. #endregion
  31.  
  32. //This will great the User
  33. SpeechSynthesizer synth = new SpeechSynthesizer();
  34. //synth.Speak("Welcome To Jarvis Version one point zero");
  35.  
  36.  
  37. //Infinate while Loop
  38. while (true)
  39. {
  40. //Get the Current Performance Counter Values
  41. int CurrentCpuPercentage = (int)perfCpuCount.NextValue();
  42. int CurrentAvailableMemory = (int)perfMemCount.NextValue();
  43.  
  44. //Every 1 second, print the CPU percentage, Memory Available and System Up time to the screen
  45.  
  46. Console.WriteLine("CPU Load: %{0}", CurrentCpuPercentage);
  47. Console.WriteLine("Available Memory: {0}MB", CurrentAvailableMemory);
  48. //Only tell us if the CPU is above 80% usage
  49. if (CurrentCpuPercentage > 80)
  50. {
  51. String CpuLoadVocalMessage = String.Format("CPU Load is {0} percent", CurrentCpuPercentage);
  52. synth.Speak(CpuLoadVocalMessage);
  53. }
  54. //Only tell us if the Availble Memory is below 1024 megabytes
  55. if (CurrentAvailableMemory < 1024)
  56. {
  57. String MemAvailableVocalMessage = String.Format("Available Memory is {0} Megabytes", CurrentAvailableMemory);
  58. synth.Speak(MemAvailableVocalMessage);
  59. }
  60.  
  61. //Wait 1 Second before Running the Loop Again
  62. Thread.Sleep(1000);
  63.  
  64. }//End of Loop
  65.  
  66.  
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement