By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,497 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,497 IT Pros & Developers. It's quick & easy.

CPU Percentage Utilization in ASP.Net using Thread

P: n/a

I just wanted to calculate CPU Percentage Utilization in ASP.Net
application using a thread.
I have written following code:
protected void Page_Load(object sender, EventArgs e)
btnTestCPUPerc.Click += new
// button click event handler
void btnTestCPUPerc_Click(object sender, EventArgs e)
// Create thread to calculate CPU Perc Usage
Thread t = new Thread(new ThreadStart(ThreadProc));
t.IsBackground = true;
// Start inserting database tables
SqlConnection insertConn = new SqlConnection();
insertConn.ConnectionString = "Data Source=localhost;Initial
Catalog=master;Integrated Security=SSPI;";
SqlCommand insertComm = new SqlCommand();
insertComm.CommandText = "INSERT INTO [master]..[TestTable]
SELECT Guid, Name FROM [temp]..[NewTable]";
insertComm.Connection = insertConn;
int i = 0;
while( i < 10000 )
public static void ThreadProc()
// Calculate CPU Perc Usage
PerformanceCounter pc = new PerformanceCounter("Processor", "%
Processor Time", "_Total");
float cpuperc = pc.NextValue();
if (double.Parse(cpuperc.ToString()) 10)
// Log event if CPU Perc Usage 10
EventLog log = new EventLog("Application");
log.WriteEntry("CPU Percentage is greater than 10%.
Current CPU Percentage is: " + double.Parse(cpuperc.ToString()));
I am inserting rows from one table to other and in the mean time I
want to raise an event if CPU % goes above 10.
Please help me out.
Thanks in adv.
Dec 15 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.