BrandonSpendlove

Techne - Application for CPU and GPU

Nov 10th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11. using System.Management;
  12. using System.Diagnostics;
  13.  
  14. namespace Techne
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.  
  19.         public static bool techneHome;
  20.         public static bool cpuMenu;
  21.         public static bool gpuMenu;
  22.         public static bool ramMenu;
  23.  
  24.         public static int cpuSpeedLoop;
  25.  
  26.         public static int cpuClockSpeed;
  27.         public static decimal cpuClockSpeedNew;
  28.  
  29.         public static int lvl2CacheSize;
  30.         public static int lvl2CacheSpeed;
  31.         public static int lvl3CacheSize;
  32.         public static int lvl3CacheSpeed;
  33.  
  34.         //Techne Website Homepage on startup
  35.  
  36.         public static string techneHomeWebsite = "http://brandonspendlove.wix.com/technecomputers";
  37.  
  38.         //CPU Information (Processor)
  39.  
  40.         ManagementObjectSearcher cpuInfo =
  41.         new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
  42.  
  43.         public PerformanceCounter cpuCounter;
  44.         public PerformanceCounter cpuPerf; // = new PerformanceCounter("Processor Information","% of Maximum Frequency","_Total");
  45.         public PerformanceCounter cpuFreq;
  46.         public PerformanceCounter cpuIdleTime;
  47.  
  48.         public Form1()
  49.         {
  50.             InitializeComponent();
  51.  
  52.             webBrowser1.Navigate(techneHomeWebsite);
  53.             textBox15.Text = techneHomeWebsite;
  54.  
  55.             techneHome = true;
  56.  
  57.             //Hide Controls that aren't on the HOMEPAGE
  58.  
  59.             #region Hide Controls that don't appear on HOMEPAGE
  60.  
  61.             label1.Hide();
  62.             textBox1.Hide();
  63.             label2.Hide();
  64.             textBox2.Hide();
  65.             label3.Hide();
  66.             textBox3.Hide();
  67.             label4.Hide();
  68.             textBox4.Hide();
  69.             label5.Hide();
  70.             textBox5.Hide();
  71.  
  72.             //L2 & 3 Cache ammount and speed
  73.  
  74.             label6.Hide();
  75.             label7.Hide();
  76.             label8.Hide();
  77.             label9.Hide();
  78.             textBox6.Hide();
  79.             textBox7.Hide();
  80.             textBox8.Hide();
  81.             textBox9.Hide();
  82.  
  83.             //Help Button
  84.             button5.Hide();
  85.  
  86.             // CPU Usage
  87.  
  88.             label10.Hide();
  89.             textBox10.Hide();
  90.  
  91.             // Architecture
  92.  
  93.             label11.Hide();
  94.             textBox11.Hide();
  95.  
  96.             // CPU Performance
  97.  
  98.             label12.Hide();
  99.             textBox12.Hide();
  100.  
  101.             // CPU Current Speed
  102.  
  103.             label13.Hide();
  104.             textBox13.Hide();
  105.  
  106.             // CPU Idle Time
  107.  
  108.             label14.Hide();
  109.             textBox14.Hide();
  110.  
  111.             #endregion
  112.  
  113.             //****************************************//
  114.  
  115.  
  116.             //Boolean Values for Application to know which page the user has selected....//
  117.  
  118.             if (techneHome == true)
  119.             {
  120.                 cpuMenu = false;
  121.                 gpuMenu = false;
  122.                 ramMenu = false;
  123.             }
  124.  
  125.             if (cpuMenu == true)
  126.             {
  127.                 techneHome = false;
  128.                 gpuMenu = false;
  129.                 ramMenu = false;
  130.             }
  131.  
  132.             if (gpuMenu == true)
  133.             {
  134.                 techneHome = false;
  135.                 cpuMenu = false;
  136.                 ramMenu = false;
  137.             }
  138.  
  139.             if (ramMenu == true)
  140.             {
  141.                 techneHome = false;
  142.                 cpuMenu = false;
  143.                 gpuMenu = false;
  144.             }
  145.  
  146.             //*************************************************************************//
  147.  
  148.             //CPU Loop information for usage
  149.  
  150.             TestSetup();
  151.             InitialiseCPUCounter();
  152.             InitCpuFreq();
  153.             InitCpuIdle();
  154.  
  155.             //*****************************//
  156.  
  157.             //**********CPU Counters Custom********//
  158.  
  159.  
  160.             //*************************************//
  161.  
  162.             //CPU Information attach to boxes.............//
  163.  
  164.  
  165.             #region CPU Menu Page Information and Attaching
  166.  
  167.             foreach (ManagementObject mo in cpuInfo.Get())
  168.             {
  169.                 // CPU Model Name
  170.                 textBox1.AppendText(string.Format("{0}", (string)(mo["Name"])));
  171.  
  172.                 // CPU Clock Speed converting to Ghz
  173.                 cpuClockSpeed = Convert.ToInt32(mo["MaxClockSpeed"]);
  174.                 cpuClockSpeedNew = (decimal)cpuClockSpeed / 1000;
  175.                 textBox2.AppendText(cpuClockSpeedNew.ToString() + "Ghz");
  176.  
  177.                 // Number of Cores on CPU
  178.                 textBox3.AppendText(string.Format("{0}", mo["NumberOfCores"]).ToString());
  179.  
  180.                 // Architecture of CPU
  181.                 textBox4.AppendText(string.Format("{0}", (ushort)mo["Architecture"]));
  182.  
  183.                 // Number of Threads on CPU
  184.                 textBox5.AppendText(string.Format("{0}", mo["NumberOfLogicalProcessors"]).ToString());
  185.  
  186.                 //L2 Cache Size and Speed
  187.                 lvl2CacheSize = Convert.ToInt32(mo["L2CacheSize"]);
  188.                 lvl2CacheSize = (lvl2CacheSize / 1000);
  189.                 textBox6.AppendText(lvl2CacheSize.ToString() + " MB");
  190.  
  191.                 lvl2CacheSpeed = Convert.ToInt32(mo["L2CacheSpeed"]);
  192.                 lvl2CacheSpeed = (lvl2CacheSpeed / 1000);
  193.                 textBox7.AppendText(lvl2CacheSpeed.ToString() + " MB");
  194.  
  195.                 //********************************************************//
  196.                 //L3 Cache Size and Speed
  197.                 lvl3CacheSize = Convert.ToInt32(mo["L3CacheSize"]);
  198.                 lvl3CacheSize = (lvl3CacheSize / 1000);
  199.                 textBox8.AppendText(lvl3CacheSize.ToString() + " MB");
  200.  
  201.                 lvl3CacheSpeed = Convert.ToInt32(mo["L3CacheSpeed"]);
  202.                 lvl3CacheSpeed = (lvl3CacheSpeed / 1000);
  203.                 textBox9.AppendText(lvl3CacheSpeed.ToString() + " MB");
  204.  
  205.                 if (textBox6.Text == "0 MB")
  206.                 {
  207.                     textBox6.Clear();
  208.                     textBox6.AppendText("Error");
  209.                 }
  210.                 if (textBox7.Text == "0 MB" )
  211.                 {
  212.                     textBox7.Clear();
  213.                     textBox7.AppendText("Error");
  214.                 }
  215.                 if (textBox8.Text == "0 MB")
  216.                 {
  217.                     textBox8.Clear();
  218.                     textBox8.AppendText("Error");
  219.                 }
  220.                 if (textBox9.Text == "0 MB")
  221.                 {
  222.                     textBox9.Clear();
  223.                     textBox9.AppendText("Error");
  224.                 }
  225.  
  226.                 //***************************************************//
  227.  
  228.                 //Status
  229.  
  230.                 textBox11.AppendText(string.Format("{0}", (ushort)mo["CpuStatus"]));
  231.  
  232.  
  233.             }
  234.  
  235.             #endregion
  236.  
  237.             //*******************************************//
  238.         }
  239.  
  240.         private void Form1_Load(object sender, EventArgs e)
  241.         {
  242.         }
  243.  
  244.         //Web Browser on HOMEPAGE
  245.  
  246.         private void NavigateToPage()
  247.         {
  248.             toolStripStatusLabel1.Text = "Navigation Started";
  249.             button6.Enabled = false;
  250.             textBox15.Enabled = false;
  251.             webBrowser1.Navigate(textBox15.Text);
  252.         }
  253.  
  254.         //Load page buttons (Different pages, HOMEPAGE, CPU, GPU and RAM)**********************************//
  255.  
  256.  
  257.         #region Menu Buttons
  258.  
  259.  
  260.         //Techne Menu Page............................//
  261.  
  262.         #region Techne Homepage Button
  263.  
  264.         private void button1_Click(object sender, EventArgs e)
  265.         {
  266.             techneHome = true;
  267.  
  268.             //CPU
  269.  
  270.             label1.Hide();
  271.             textBox1.Hide();
  272.             label2.Hide();
  273.             textBox2.Hide();
  274.             label3.Hide();
  275.             textBox3.Hide();
  276.             label4.Hide();
  277.             textBox4.Hide();
  278.             label5.Hide();
  279.             textBox5.Hide();
  280.  
  281.             //Help Button on CPU page
  282.  
  283.             button5.Hide();
  284.  
  285.             //L2 & 3 Cache ammount and speed
  286.  
  287.             label6.Hide();
  288.             label7.Hide();
  289.             label8.Hide();
  290.             label9.Hide();
  291.             textBox6.Hide();
  292.             textBox7.Hide();
  293.             textBox8.Hide();
  294.             textBox9.Hide();
  295.  
  296.             //CPU Usage
  297.  
  298.             label10.Hide();
  299.             textBox10.Hide();
  300.  
  301.             //Status
  302.  
  303.             label11.Hide();
  304.             textBox11.Hide();
  305.  
  306.             // CPU Performance
  307.  
  308.             label12.Hide();
  309.             textBox12.Hide();
  310.  
  311.             // CPU Current Speed
  312.  
  313.             label13.Hide();
  314.             textBox13.Hide();
  315.  
  316.             // CPU Idle Time
  317.  
  318.             label14.Hide();
  319.             textBox14.Hide();
  320.  
  321.             // Web Browser...
  322.  
  323.             webBrowser1.Show();
  324.             textBox15.Show();
  325.             button6.Show();
  326.             statusStrip1.Show();
  327.         }
  328.  
  329.         #endregion
  330.  
  331.         //*******************************************//
  332.  
  333.  
  334.         //CPU Menu page.............................//
  335.  
  336.         #region CPU Menu Button
  337.  
  338.         //CPU page button
  339.         private void button2_Click(object sender, EventArgs e)
  340.         {
  341.             cpuMenu = true;
  342.  
  343.             //CPU
  344.  
  345.             label1.Show();
  346.             textBox1.Show();
  347.             label2.Show();
  348.             textBox2.Show();
  349.             label3.Show();
  350.             textBox3.Show();
  351.             label4.Show();
  352.             textBox4.Show();
  353.             label5.Show();
  354.             textBox5.Show();
  355.  
  356.             //Help Button
  357.  
  358.             button5.Show();
  359.  
  360.             //L2 & 3 Cache ammount and speed
  361.  
  362.             label6.Show();
  363.             label7.Show();
  364.             label8.Show();
  365.             label9.Show();
  366.             textBox6.Show();
  367.             textBox7.Show();
  368.             textBox8.Show();
  369.             textBox9.Show();
  370.  
  371.             //CPU Usage
  372.             label10.Show();
  373.             textBox10.Show();
  374.  
  375.             //Status
  376.  
  377.             label11.Show();
  378.             textBox11.Show();
  379.  
  380.             // CPU Performance
  381.  
  382.             label12.Show();
  383.             textBox12.Show();
  384.  
  385.             // CPU Current Speed
  386.  
  387.             label13.Show();
  388.             textBox13.Show();
  389.  
  390.             // CPU Idle Time
  391.  
  392.             label14.Show();
  393.             textBox14.Show();
  394.  
  395.             // Web Browser...
  396.  
  397.             webBrowser1.Hide();
  398.             textBox15.Hide();
  399.             button6.Hide();
  400.             statusStrip1.Hide();
  401.  
  402.         }
  403.  
  404.         #endregion
  405.  
  406.         //*****************************************//
  407.  
  408.  
  409.  
  410.         //GPU Menu Page.............................//
  411.  
  412.         #region GPU Menu Button
  413.  
  414.         //GPU Page Button*********************************************************************************//
  415.  
  416.         private void button3_Click(object sender, EventArgs e)
  417.         {
  418.             gpuMenu = true;
  419.  
  420.             //CPU
  421.  
  422.             label1.Hide();
  423.             textBox1.Hide();
  424.             label2.Hide();
  425.             textBox2.Hide();
  426.             label3.Hide();
  427.             textBox3.Hide();
  428.             label4.Hide();
  429.             textBox4.Hide();
  430.             label5.Hide();
  431.             textBox5.Hide();
  432.  
  433.             //L2 & 3 Cache ammount and speed
  434.  
  435.             label6.Hide();
  436.             label7.Hide();
  437.             label8.Hide();
  438.             label9.Hide();
  439.             textBox6.Hide();
  440.             textBox7.Hide();
  441.             textBox8.Hide();
  442.             textBox9.Hide();
  443.  
  444.             //Help Button
  445.  
  446.             button5.Hide();
  447.  
  448.             //CPU Usage
  449.  
  450.             label10.Hide();
  451.             textBox10.Hide();
  452.  
  453.             //Status
  454.  
  455.             label11.Hide();
  456.             textBox11.Hide();
  457.  
  458.             // CPU Performance
  459.  
  460.             label12.Hide();
  461.             textBox12.Hide();
  462.  
  463.             // CPU Current Speed
  464.  
  465.             label13.Hide();
  466.             textBox13.Hide();
  467.  
  468.             // CPU Idle Time
  469.  
  470.             label14.Hide();
  471.             textBox14.Hide();
  472.  
  473.  
  474.             // Web Browser...
  475.  
  476.             webBrowser1.Hide();
  477.             textBox15.Hide();
  478.             button6.Hide();
  479.             statusStrip1.Hide();
  480.  
  481.         }
  482.  
  483.         #endregion
  484.  
  485.         //*******************************************//
  486.  
  487.         #endregion
  488.  
  489.         private void label1_Click(object sender, EventArgs e)
  490.         {
  491.  
  492.         }
  493.  
  494.         private void textBox5_TextChanged(object sender, EventArgs e)
  495.         {
  496.  
  497.         }
  498.  
  499.         private void textBox7_TextChanged(object sender, EventArgs e)
  500.         {
  501.  
  502.         }
  503.  
  504.         private void button6_Click(object sender, EventArgs e)
  505.         {
  506.  
  507.         }
  508.  
  509.         private void textBox10_TextChanged(object sender, EventArgs e)
  510.         {
  511.  
  512.         }
  513.  
  514.         // CPU Timers for refreshing the usage etc... //
  515.         //*******************************************//
  516.  
  517.         //CPU Usage
  518.  
  519.         private void InitialiseCPUCounter()
  520.         {
  521.             Thread.Sleep(100);
  522.             cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
  523.         }
  524.  
  525.         private void timer1_Tick(object sender, EventArgs e)
  526.         {
  527.             this.textBox10.Text = "" +Convert.ToInt32(cpuCounter.NextValue()).ToString() +"%";
  528.         }
  529.  
  530.         //CPU Frequency (Current Speed)
  531.  
  532.         private void InitCpuFreq()
  533.         {
  534.             Thread.Sleep(100);
  535.             cpuFreq = new PerformanceCounter("Processor Information", "Processor Frequency", "_Total");
  536.         }
  537.  
  538.         private void timer2_Tick(object sender, EventArgs e)
  539.         {
  540.             this.textBox13.Text = "" + Convert.ToInt32(cpuFreq.NextValue()).ToString() + " - Mhz";
  541.         }
  542.  
  543.         //CPU Performance
  544.  
  545.  
  546.         private void TestSetup()
  547.         {
  548.             Thread.Sleep(100);
  549.  
  550.             cpuPerf = new PerformanceCounter("Processor Information", "% Processor Performance", "_Total");
  551.  
  552.             //cpuTest.CategoryName = "Processor Performance";
  553.             //cpuTest.CounterName = "Processor Frequency";
  554.             // cpuTest.InstanceName = "PPM_Processor_0";
  555.         }
  556.  
  557.         private void timer3_Tick(object sender, EventArgs e)
  558.         {
  559.             this.textBox12.Text = "" + Convert.ToInt32(cpuPerf.NextValue()).ToString() +"%";
  560.         }
  561.  
  562.         // Idle Time....
  563.  
  564.         private void InitCpuIdle()
  565.         {
  566.             Thread.Sleep(100);
  567.             cpuIdleTime = new PerformanceCounter("Processor Information","% Idle Time","_Total");
  568.         }
  569.  
  570.         private void timer4_Tick(object sender, EventArgs e)
  571.         {
  572.             this.textBox14.Text = "" + Convert.ToInt32(cpuIdleTime.NextValue()).ToString() + "%";
  573.         }
  574.  
  575.         //*******************************************************//
  576.  
  577.         private void label10_Click(object sender, EventArgs e)
  578.         {
  579.  
  580.         }
  581.  
  582.         private void textBox11_TextChanged(object sender, EventArgs e)
  583.         {
  584.  
  585.         }
  586.  
  587.         private void label11_Click(object sender, EventArgs e)
  588.         {
  589.  
  590.         }
  591.  
  592.         private void textBox11_TextChanged_1(object sender, EventArgs e)
  593.         {
  594.  
  595.         }
  596.  
  597.         // Help form appear...
  598.         private void button5_Click(object sender, EventArgs e)
  599.         {
  600.             Form2 form2 = new Form2();
  601.             form2.Show();
  602.         }
  603.  
  604.         private void textBox12_TextChanged(object sender, EventArgs e)
  605.         {
  606.  
  607.         }
  608.  
  609.         private void textBox12_TextChanged_1(object sender, EventArgs e)
  610.         {
  611.  
  612.         }
  613.  
  614.         private void textBox13_TextChanged(object sender, EventArgs e)
  615.         {
  616.  
  617.         }
  618.  
  619.         private void textBox10_TextChanged_1(object sender, EventArgs e)
  620.         {
  621.  
  622.         }
  623.  
  624.         private void label12_Click(object sender, EventArgs e)
  625.         {
  626.  
  627.         }
  628.  
  629.         private void textBox13_TextChanged_1(object sender, EventArgs e)
  630.         {
  631.  
  632.         }
  633.  
  634.         private void textBox14_TextChanged(object sender, EventArgs e)
  635.         {
  636.  
  637.         }
  638.  
  639.         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  640.         {
  641.             button6.Enabled = true;
  642.             textBox15.Enabled = true;
  643.             toolStripStatusLabel1.Text = "Navigation Complete";
  644.         }
  645.  
  646.         private void textBox15_TextChanged(object sender, EventArgs e)
  647.         {
  648.  
  649.         }
  650.  
  651.         private void button6_Click_1(object sender, EventArgs e)
  652.         {
  653.             NavigateToPage();
  654.         }
  655.  
  656.         private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  657.         {
  658.  
  659.         }
  660.  
  661.         // Webbrowser Keypress (HOMEPAGE)
  662.         private void textBox15_KeyPress(object sender, KeyPressEventArgs e)
  663.         {
  664.             if (e.KeyChar == (char)ConsoleKey.Enter)
  665.             {
  666.                 NavigateToPage();
  667.             }
  668.         }
  669.  
  670.         private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
  671.         {
  672.             if (e.CurrentProgress > 0 && e.MaximumProgress > 0)
  673.             {
  674.                 toolStripProgressBar1.ProgressBar.Value = (int)(e.CurrentProgress * 100 / e.MaximumProgress);
  675.             }
  676.         }
  677.     }
  678. }
Advertisement
Add Comment
Please, Sign In to add comment