English 中文(简体)
执行台 。 nextValue () 丢弃无效操作例外
原标题:PerformanceCounter.NextValue() throws InvalidOperationException

这是创建性能计数器的代码:

var ftpPerfCounter = new PerformanceCounter("FTP Service", "Current Connections", "_Total");

这就是例外发生的地方:

int cnt = (int)Math.Round(ftpPerfCounter.NextValue());

s 这里的 Expeption 消息 :

"Error Message: The Counter layout for the Category specified is invalid, a counter of the type: AverageCount64, AverageTimer32, CounterMultiTimer, CounterMultiTimerInverse, CounterMultiTimer100Ns, CounterMultiTimer100NsInverse, RawFraction, or SampleFraction has to be immediately followed by any of the base counter types: AverageBase, CounterMultiBase, RawBase or SampleBase."

错误信息是相当隐秘的。 我不知道今后能做些什么来避免例外。

详细

This happens on Windows Server 2008 R2 64-bit OS. The FTP Server is IIS.

问题回答

至少在我的Windows Server 2008 R2 和 IS 7.5 上, 性能对应类别被称为“微软FTP Service ”, 而不是“FTP Service ” 。 也许不同的OS/IIS版本不同, 但它很容易检查。

在目标服务器/机器上:

  1. Run "Performance Monitor"
  2. Click "Performance Monitor in the left navigation pane
  3. Click the plus icon to Add a performance counter
  4. Scroll down the list of available counters. Look for FTP or Microsoft FTP to see if it exists... note if you don t have Microsoft FTP services installed you won t see the performance counter.
  5. Once found, select it, and you ll see a list of specific counter instances you can query. One of those instances is the _Total you were interested in.

当然,这也证明,反演反演 与你的代码无关。这是一件好事,你应该知道!

关于如何在C#/.NET中与 < a href=" >绩效对计系统合作的具体最佳做法,请见这个堆积流站 。

我没有在我的个人电脑上安装IIS, 但如果我安装了,这就是我想尝试的:

  1. Try to use Visual Studio s code generator for WMI by drag-and-drop from Server Explorer. Inspect the generated code and see if there are any differences from your code.
  2. Use reflector to see where the exception is thrown, set a custom breakpoint inside BCL, and reproduce. Then analyze the call stack contents and look for suspicious code paths or unexpected state.

他们似乎已经解决了一个类似的问题 这里。也许你必须设置一个基础柜台?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签