简体   繁体   中英

How to determine total processor time for a process in C#?

I am using the Process.TotalProcessorTime command to get the total process time for that process. But it doesn't work properly for the same process when it runs multiple times. Can anyone provide the proper solution or suggest a new method in C#?

Look into the % Processor time performance counter for the process. Details can be found in - http://pandeysk.wordpress.com/2013/01/02/performance-measurement-in-net/

If you run an application multiple times, they are all different processes . Are you trying to record the total time for an application? You'd need to monitor the system constantly and check when the process runs, not easy. Or you can implement this timing mechanism in the application itself.

相反,您可以将流程附加到perfmon,添加性能计数器并获取该流程的处理器时间。

I think best approach is to use

// Get all instances of "myprocess" actually running on the local computer.

Process[] LocProcByName = Process.GetProcessesByName("myprocess");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM