473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

CPU % Utilization on ASP.Net in Threads

Hi,

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
EventHandler(btnTestCPUPerc_Click);
}

// 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;
t.Start();

// Start inserting database tables

SqlConnection insertConn = new SqlConnection();
insertConn.ConnectionString = "Data Source=localhost;Initial
Catalog=master;Integrated Security=SSPI;";

insertConn.Open();

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 )
{
insertComm.ExecuteNonQuery();
i++;
}
}

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.

PI
Dec 15 '07 #1
0 1010

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Joe Kraft | last post by:
I'm hoping someone can help me out. We're running a website that uses XML/XSLT transformations, VB.Net and an Oracle database. Currently the site cannot support more than 6-7 users at a time...
3
by: Dathon | last post by:
I have a Windows service that's built with .NET. The process is meant to run in the background and not suck up too much CPU time. I set the thread priority for the various threads in the service...
3
by: Dathon | last post by:
I have a Windows service that's built with .NET. The process is meant to run in the background and not suck up too much CPU time. I set the thread priority for the various threads in the service...
1
by: Pawan.Ghildiyal | last post by:
Hi everybody As we know that replication process uses 3 threads- 1. Master thread (Binlog Dump) 2. I/O thread 3. Sql Thread Now I have some confusion regarding these thing -- - In peek...
1
by: Kaheru | last post by:
memory utilization increase? This is because when i try to keep track of the CPU utilization and memory utilization of my FTP server process (ftpserver.exe), the CPU utilization increase, but the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.