473,660 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(objec t sender, EventArgs e)
{
btnTestCPUPerc. Click += new
EventHandler(bt nTestCPUPerc_Cl ick);
}
// button click event handler
void btnTestCPUPerc_ Click(object sender, EventArgs e)
{
// Create thread to calculate CPU Perc Usage
Thread t = new Thread(new ThreadStart(Thr eadProc));
t.IsBackground = true;
t.Start();
// Start inserting database tables
SqlConnection insertConn = new SqlConnection() ;
insertConn.Conn ectionString = "Data Source=localhos t;Initial
Catalog=master; Integrated Security=SSPI;" ;
insertConn.Open ();
SqlCommand insertComm = new SqlCommand();
insertComm.Comm andText = "INSERT INTO [master]..[TestTable]
SELECT Guid, Name FROM [temp]..[NewTable]";
insertComm.Conn ection = insertConn;
int i = 0;
while( i < 10000 )
{
insertComm.Exec uteNonQuery();
i++;
}
}
public static void ThreadProc()
{
// Calculate CPU Perc Usage
PerformanceCoun ter pc = new PerformanceCoun ter("Processor" , "%
Processor Time", "_Total");
float cpuperc = pc.NextValue();
if (double.Parse(c puperc.ToString ()) 10)
{
// Log event if CPU Perc Usage 10
EventLog log = new EventLog("Appli cation");
log.WriteEntry( "CPU Percentage is greater than 10%.
Current CPU Percentage is: " + double.Parse(cp uperc.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 1684

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

Similar topics

4
6777
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 server.the os is windows 2000 professional. the same problem occurs online as more people open there applet (ultimately it hangs).
0
1523
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 before the CPU gets pegged at 100% utilization. The XML/XSL document get transformed on the server and averages 200k when it runs through the transformNode method. I've created an IISState log file and noticed the following threads taking up a lot...
3
3753
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 to Below Normal, but I'm still getting reports that the service is making a noticable impact on overall machine performance. I stuck some Thread.Sleep calls in a various places in the code, but that doesn't help much, since the service makes...
1
2266
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, someone gave me a component that spun off that misbehaved and
1
3327
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 hours what will be the cpu and memory utilization of these threads
2
1838
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 with most of our apps in a custom app pool to recycle memory every 800MB.
11
3469
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 MouseMove, the form is resized around a 30-100 times in one second. This leads to a high CPU utilization and all other application comes to a stand still. The form does not have any controls i.e. buttons, text boxes etc. It is completely...
4
2639
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. Really, I don't know the guy but just found it via Google. I guess I don't need to post this anymore but just in case someone else is looking for the info, here it is. It's in C# but nobody is perfect. ...
7
13968
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 following code from web, but it is not running properly and also i have no idea what it will do, i heared that there will be used performance monitoring and donot know how to use it. please help me with coding instructins. public...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.