using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CsPerformanceCounter { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Shown(object sender, EventArgs e) { this.Timer1.Interval = 1000; this.Timer1.Enabled = true; } private void Timer1_Tick(object sender, EventArgs e) { this.Timer1.Enabled = false; try { float processTime = this.PerformanceCounter1.NextValue(); if (this.CPU_ProgressBar.Maximum < processTime) { this.CPU_ProgressBar.Maximum = (int)processTime; } this.CPU_ProgressBar.Value = (int)processTime; } catch (Exception ex) { MessageBox.Show( ex.Message, this.Text, MessageBoxButtons.OK); } this.Timer1.Enabled = true; } } }