Click here to Skip to main content
15,898,134 members
Home / Discussions / C#
   

C#

 
GeneralRe: easy newbie question Pin
lost in transition 20-Sep-07 10:47
lost in transition 20-Sep-07 10:47 
GeneralRe: easy newbie question Pin
Scott Dorman20-Sep-07 10:51
professionalScott Dorman20-Sep-07 10:51 
AnswerRe: easy newbie question Pin
Scott Dorman20-Sep-07 10:36
professionalScott Dorman20-Sep-07 10:36 
GeneralRe: easy newbie question Pin
Pete O'Hanlon20-Sep-07 11:26
mvePete O'Hanlon20-Sep-07 11:26 
GeneralRe: easy newbie question Pin
Scott Dorman20-Sep-07 11:32
professionalScott Dorman20-Sep-07 11:32 
AnswerRe: easy newbie question Pin
shwaguy20-Sep-07 12:06
shwaguy20-Sep-07 12:06 
QuestionGridView Row updating Pin
ss.mmm20-Sep-07 9:57
ss.mmm20-Sep-07 9:57 
QuestionPerformanceCounter problems Pin
JMichael246820-Sep-07 8:53
JMichael246820-Sep-07 8:53 
I have been trying to come up with a way to track the CPU% usage of applications that I have running on different machines in different locations. In some instances there are multiple copies of the application running on the same machine. I was hoping to use the performancecounter to get the cpu% for these applications. However, I cannot get accurate results from machines running multiple copies of the application because the instance or names of the processes are the same. For instance, if I have four copies of an application running on one machine, my results may look like:

appName 100%
appName 100%
appName 100%
appName 100%

When in reality it should be:

appName 1%
appName 2%
appName 100%
appName 4%

Here is the code that I was using. Does anyone have any suggestions?

<br />
public string CPUUsage(string workingDirectory)<br />
{<br />
     string procName = ConfigurationManager.AppSettings["MonitorEXE_Name"];<br />
<br />
    string cpuUsage = "0.00%";<br />
	<br />
	// get the list of all processes by that name<br />
    Process[] processes = Process.GetProcessesByName(procName);<br />
	<br />
	if (processes.Length > 0)<br />
    {<br />
        string thisProcessWorkingDirectory = workingDirectory + "\\" + procName + ".exe";<br />
		foreach (Process process in processes)<br />
        {<br />
            //is this the process you're looking for<br />
            if (process.Modules[0].FileName.ToUpper() == thisProcessWorkingDirectory.ToUpper())<br />
            {<br />
				//I WANTED TO USE THE PROCESSID TO GET CPU USAGE<br />
                Process processToMonitor = Process.GetProcessById(process.Id);<br />
				<br />
				using (PerformanceCounter pcProcess = new PerformanceCounter("Process", "% Processor Time", processToMonitor.ProcessName))<br />
                {<br />
                            <br />
                    pcProcess.NextValue();<br />
                    System.Threading.Thread.Sleep(1000);<br />
                    cpuUsage = pcProcess.NextValue().ToString("f2") + "%";<br />
<br />
                }				<br />
            }<br />
		}	<br />
	}<br />
	return cpuUsage;<br />
}

AnswerRe: PerformanceCounter problems Pin
JMichael246821-Sep-07 4:36
JMichael246821-Sep-07 4:36 
QuestionSpeed up Treeview [Solved] Pin
DaveyM6920-Sep-07 8:52
professionalDaveyM6920-Sep-07 8:52 
AnswerRe: Speed up Treeview Pin
Dave Kreskowiak20-Sep-07 9:12
mveDave Kreskowiak20-Sep-07 9:12 
GeneralRe: Speed up Treeview Pin
DaveyM6920-Sep-07 10:55
professionalDaveyM6920-Sep-07 10:55 
GeneralRe: Speed up Treeview Pin
Scott Dorman20-Sep-07 10:58
professionalScott Dorman20-Sep-07 10:58 
GeneralRe: Speed up Treeview Pin
DaveyM6920-Sep-07 11:13
professionalDaveyM6920-Sep-07 11:13 
AnswerRe: Speed up Treeview [modified] Pin
Scott Dorman20-Sep-07 10:56
professionalScott Dorman20-Sep-07 10:56 
GeneralRe: Speed up Treeview Pin
Pete O'Hanlon20-Sep-07 11:19
mvePete O'Hanlon20-Sep-07 11:19 
GeneralRe: Speed up Treeview Pin
Scott Dorman20-Sep-07 11:37
professionalScott Dorman20-Sep-07 11:37 
GeneralRe: Speed up Treeview Pin
DaveyM6920-Sep-07 11:43
professionalDaveyM6920-Sep-07 11:43 
AnswerRe: Speed up Treeview Pin
DaveyM6920-Sep-07 11:31
professionalDaveyM6920-Sep-07 11:31 
GeneralRe: Speed up Treeview Pin
Scott Dorman20-Sep-07 18:26
professionalScott Dorman20-Sep-07 18:26 
GeneralRe: Speed up Treeview Pin
DaveyM6921-Sep-07 1:05
professionalDaveyM6921-Sep-07 1:05 
GeneralRe: Speed up Treeview Pin
Scott Dorman21-Sep-07 4:49
professionalScott Dorman21-Sep-07 4:49 
GeneralRe: Speed up Treeview Pin
Pete O'Hanlon21-Sep-07 9:12
mvePete O'Hanlon21-Sep-07 9:12 
GeneralRe: Speed up Treeview Pin
DaveyM6921-Sep-07 3:36
professionalDaveyM6921-Sep-07 3:36 
GeneralRe: Speed up Treeview Pin
Scott Dorman21-Sep-07 4:51
professionalScott Dorman21-Sep-07 4:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.