我在我的C#项目中使用了windows性能监视器类,通过网卡测量字节数、发送数等,一切似乎都很正常。我使用网络索引号来确定用于记录性能数据的网络接口。我可以通过命令提示符看到网络索引号(netsh int ipv4 show int)
但是,我已经连接到vpn并更改了网络索引号以引用vpn,当我尝试读取性能监视器"nextValue()“时,我得到了一个异常。
发布于 2012-10-07 18:48:10
尝试使用powershell性能计数器,它们有很强的功能...
power shell命令的方法指南(import-counter)可以在这里找到。
http://ss64.com/ps/
我在下面添加了一些示例代码,让您了解它们是如何调用的:
private static void LoadBLG(string CounterPath)
{
PowerShell ps = PowerShell.Create();
ps.AddCommand("import-counter");
ps.AddArgument(CounterPath);
Console.WriteLine(CounterPath);
Console.WriteLine("------------------------");
foreach (PSObject result in ps.Invoke())
{
if (result.ImmediateBaseObject is PerformanceCounterSampleSet)
{
PerformanceCounterSampleSet Counters = result.ImmediateBaseObject as PerformanceCounterSampleSet;
foreach (PerformanceCounterSample sample in Counters.CounterSamples)
Console.WriteLine("{0,-20}{1}",
sample.Path, sample.RawValue);
}
} // End foreach.
祝你好运,马修
https://stackoverflow.com/questions/12766863
复制相似问题