gpt4 book ai didi

c# - 监视特定进程的网络性能

转载 作者:太空狗 更新时间:2023-10-29 19:47:59 25 4
gpt4 key购买 nike

我正在编写一个程序,该程序使用 .NET 性能计数器来获取特定进程的 CPU、内存和网络使用情况。

例如,为了获取 Explorer 的 CPU 和内存数据,我创建了这样的性能计数器:

PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Process";
PC.CounterName = "% Processor Time";
PC.InstanceName = "Explorer";

PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Process";
PC.CounterName = "Working Set - Private";
PC.InstanceName = "Explorer";

不幸的是,进程 categoryName 没有属性允许我获取该进程的网络使用情况。我可以使用网络接口(interface) categoryName 获取任何特定 NIC 上的整体网络使用情况,但无法将其隔离到任何给定进程。

最佳答案

我想你只能得到整个系统的网络使用情况。您可以使用此代码:

GetCounterValue(_netRecvCounters[index], "Network Interface", "Bytes Received/sec",      _instanceNames[index]):

double GetCounterValue(PerformanceCounter pc, string categoryName, string counterName, string instanceName)
{
pc.CategoryName = categoryName;
pc.CounterName = counterName;
pc.InstanceName = instanceName;
return pc.NextValue();
}

使用 PerformanceCounters,您只能获得 Microsoft 希望您有权访问的值。

关于c# - 监视特定进程的网络性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16200034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com