I'm trying to send out an alert in case when process takes more than certain % of CPU. I'm using the following code to get it:
PerformanceCoun ter pcProcess = new PerformanceCoun ter();
pcProcess.Categ oryName = "Process";
pcProcess.Count erName = "% Processor Time";
pcProcess.Insta nceName = "ProcessNam e";
pcProcess.NextV alue();
System.Threadin g.Thread.Sleep( 1000);
double d = pcProcess.NextV alue();
//Console.WriteLi ne("Process:{0 } CPU% {1}", strProcessName, d);
After that I'm using d variable to check if alert needs to be sent out or not.
But the problem is my program is running in many instances meaning all those instances have the same process name in task manager and therefore I don't know which one is which. So the point is I want each instance to check its own % process time, how do I separate them? I can get PID using Process class but how would I use it?
Or maybe you know the way to set a process name in the beginning of the code for each instance?
Also say there are 3 processes with the same name, which one's % Processor Time would PerformanceCoun ter get using the code above?
Thank you in advance!
PerformanceCoun ter pcProcess = new PerformanceCoun ter();
pcProcess.Categ oryName = "Process";
pcProcess.Count erName = "% Processor Time";
pcProcess.Insta nceName = "ProcessNam e";
pcProcess.NextV alue();
System.Threadin g.Thread.Sleep( 1000);
double d = pcProcess.NextV alue();
//Console.WriteLi ne("Process:{0 } CPU% {1}", strProcessName, d);
After that I'm using d variable to check if alert needs to be sent out or not.
But the problem is my program is running in many instances meaning all those instances have the same process name in task manager and therefore I don't know which one is which. So the point is I want each instance to check its own % process time, how do I separate them? I can get PID using Process class but how would I use it?
Or maybe you know the way to set a process name in the beginning of the code for each instance?
Also say there are 3 processes with the same name, which one's % Processor Time would PerformanceCoun ter get using the code above?
Thank you in advance!
Comment