日期:2014-05-18  浏览次数:20792 次

请教,NextValue()始终返回的0
代码如下,请指教。
为什么NextValue()返回的都是0?疑问
我是用timer空间每秒调用一次这个方法的 
C# code
        
        private void load_Monitor() 
        {

            listView1.Items.Clear();
            PerformanceCounterCategory category = new PerformanceCounterCategory("Web Service");
            int i;
            i = 0;
            foreach (string str in category.GetInstanceNames())
            {
                i++;
                PerformanceCounter counter1 = new PerformanceCounter(category.CategoryName,"Bytes Sent/sec",str);
                PerformanceCounter counter2 = new PerformanceCounter(category.CategoryName,"Files/sec",str);
                ListViewItem listItem = new ListViewItem();
                listItem.SubItems[0].Text = i.ToString();
                listItem.SubItems.Add(str);
                listItem.SubItems.Add(counter1.NextValue().ToString());
                listItem.SubItems.Add(counter2.NextValue().ToString());
                listView1.Items.Add(listItem);
            }
        }



------解决方案--------------------
foreach (string str in category.GetInstanceNames()) 确认这里没问题?
------解决方案--------------------
学习
你可以到这看下
http://www.cnblogs.com/xh831213/archive/2008/06/12/1218234.html
------解决方案--------------------
counter1.IncrementBy(value);
你要增加value才可以....