如何确定 C# 中进程的总处理器时间?
我正在使用 Process.TotalProcessorTime 命令来获取该进程的总处理时间。但当同一进程运行多次时,它就无法正常工作。任何人都可以提供正确的解决方案或建议 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#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您多次运行应用程序,它们都是不同的进程。您是否想记录申请的总时间?您需要不断监控系统并检查进程何时运行,这并不容易。或者您可以在应用程序本身中实现此计时机制。
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,添加性能计数器并获取该进程的处理器时间。
Instead you can attach the process to perfmon,add Performance counters and get the processor time for the process.
我认为最好的方法是使用
// 获取本地计算机上实际运行的“myprocess”的所有实例。
I think best approach is to use
// Get all instances of "myprocess" actually running on the local computer.
查看进程的处理器时间百分比性能计数器。详细信息可以在 - http://pandeysk.wordpress 中找到。 com/2013/01/02/performance-measurement-in-net/
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/