|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace CPU_Monitor_AddIn
{
public partial class CPUMonitor : UserControl
{
string computer = Environment.MachineName;
string configFile = @"C:\TEMP\MonitorAddIn\Monitor.xml";
CPU_Monitor_AddIn.NewDataSet ds ;
public CPUMonitor(string computerName,CPU_Monitor_AddIn.NewDataSet configDS)
{
InitializeComponent();
ds = configDS;
//Init the monitor controls.
cpuMonitor1.TextUnit = "";
cpuMonitor1.StoreMax = false;
cpuMonitor2.TextUnit = "";
cpuMonitor2.StoreMax = false;
//Init the prefCounters with the machineName.
if(computerName=="")
lblComputerName.Text = Environment.MachineName;
else
{
computer = computerName;
lblComputerName.Text = computerName;
}
this.perfCounter.MachineName = computer;
this.perfCounter1.MachineName = computer;
this.perfCounter2.MachineName = computer;
}
private void SampleTimer_Tick(object sender, EventArgs e)
{
try
{
//calculate the values of the monitors.
int num = Convert.ToInt32(Math.Ceiling((double)this.perfCounter.NextValue()));
cpuMonitor1.Value = (float)num;
toolTip1.SetToolTip(cpuMonitor1, num.ToString() + "%");
int maxMemory = Convert.ToInt32(Math.Round((double)this.perfCounter2.NextValue() / Math.Pow(1024, 2)));
cpuMonitor2.Max = maxMemory;
cpuMonitor2.Interval = maxMemory / 10;
int memory = Convert.ToInt32(Math.Ceiling((double)this.perfCounter1.NextValue()) / Math.Pow(1024, 2));
cpuMonitor2.Value = (float)memory;
toolTip1.SetToolTip(cpuMonitor2,"Commit Charge: "+ memory.ToString()+"M / " + maxMemory.ToString() + "M");
lblError.Visible = false;
}
catch (Exception ex)
{
//Show the error in the error label.
lblError.Visible = true;
}
}
private void btnSet_Click(object sender, EventArgs e)
{
try
{
//Set the computer name for the monitors and save it to the config file.
computer = txtComputer.Text;
if (computer == "")
computer = Environment.MachineName;
perfCounter.MachineName = computer;
perfCounter1.MachineName = computer;
perfCounter2.MachineName = computer;
ds.Tables[0].Rows[0]["ComputerName"] = computer;
ds.WriteXml(configFile);
lblComputerName.Text = computer;
txtComputer.Text = "";
lblError.Visible = false;
}
catch (Exception ex)
{
//Show the error in the error label.
lblError.Visible = true;
}
}
private void txtComputer_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btnSet.PerformClick();
}
}
private void pbRemote_Click(object sender, EventArgs e)
{
Process.Start("mstsc.exe", "/v:" + computer);
}
private void pbManage_Click(object sender, EventArgs e)
{
Process.Start("compmgmt.msc", "/computer=" + computer);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.