473,405 Members | 2,185 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,405 software developers and data experts.

CPU Percentage Utilization in ASP.Net using Thread

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 1665

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

Similar topics

4
by: Anks | last post by:
hi I am testing my applet to servlet communication program using appletviewer. as soon as i start the applet the cpu utilization reaches to 100%.I am using apache tomcat 4.1 application...
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...
1
by: jay | last post by:
Greetings I have a C# windows service that creates several application domains. Each app domain has it's own programs running, doing their own thing, independent of each other. Recently,...
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...
2
by: dm3281 | last post by:
Hello, all. I have 4 web servers in a farm using network load balancing service. All the web applications (there are about 50+ per server) are using ASP.NET 1.1. I have two apppools setup...
11
by: Ajith Menon | last post by:
I have created a windows application in which the form needs to be resized on the MouseMove event. The windows resize function takes a lot of CPU cycles. And as the resize function is called on the...
4
by: dgk | last post by:
For the whole machine, not a specific process. I looked at an earlier thread by Cor and Ken Tucker, but I don't find anything in the management that looks like... Oh. Here is a really good site....
7
by: balach | last post by:
hi all, i am new in .NET, some body please help me regarding calculating total cpu utilization and RAM memory utilization in percentage (Accurately) on page load event of ASP.NET. i found 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: 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: 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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.