or
using System;
using System.Diagnostics;
using System.Data;
using System.Windows.Forms;
namespace MemOV
{
public partial class FrmMain : Form
{
private PerformanceCounter cpuCounter;
private PerformanceCounter ramCounter;
public FrmMain()
{
InitializeComponent();
InitializeCpuCounter();
InitializeRamCounter();
updateTimer.Start();
}
private void UpdateTimerTick(object sender, EventArgs e)
{
this.textBox1.Text = "CPU Usage: " + Convert.ToInt32(cpuCounter.NextValue()).ToString() + "%" + " | " + "Memory Usage: " + Convert.ToInt32(ramCounter.NextValue()).ToString() + "Mb";
this.textBox2.Text = Convert.ToInt32(ramCounter.NextValue()).ToString() + "Mb";
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void InitializeCpuCounter()
{
cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
}
private void InitializeRamCounter()
{
ramCounter = new PerformanceCounter("Memory", "Available MBytes", true);
}
}
}
/// <
summary
>
/// On click event
/// </
summary
>
/// <
param
name
=
"e"
></
param
>
protected override void OnClick(EventArgs e)
{
if (this.multiClickAccepted)
base.OnClick(e);
else
{
//if the multiclick is disabled (as default) disable the button before raise any event
this.temporaryEnabled = this.Enabled;
base.Enabled = false;
base.OnClick(e);
base.Enabled = (bool)this.temporaryEnabled;
this.temporaryEnabled = null;
//after the reactivation look for any binding to restore the correct button state
if (this.DataBindings != null)
{
foreach (System.Windows.Forms.Binding b in this.DataBindings)
{
if (b.PropertyName.Equals("Enabled"))
b.ReadValue();
}
}
}
}
summaryItem.Name =
"TimeWorked"
summaryItem.AggregateExpression =
"SUM(MinutesWorked)"
summaryItem.FormatString =
"{0:hh}:{0:mm} = {0}"