Performance Counter - System.InvalidOperationException: Category does not exist

前端 未结 5 1459
花落未央
花落未央 2020-12-08 17:19

I have following class that returns number of current Request per Second of IIS. I call RefreshCounters every minute in order to keep Requests per Second value refreshed (be

5条回答
  •  醉酒成梦
    2020-12-08 17:48

    I don't know, if this passes you .. I've read article PerformanceCounter.NextValue Method

    And there was a comment:

    // If the category does not exist, create the category and exit.
    // Performance counters should not be created and immediately used.
    // There is a latency time to enable the counters, they should be created
    // prior to executing the application that uses the counters.
    // Execute this sample a second time to use the category.
    

    So, I have a question, which can lead to answer: isn't call to a RequestsPerSecond method happends too early? Also, I would suggest you to to try check if the Category doesn't exists and log the info somewhere, so we can analyze it and determine which conditions we have and how often that happends.

提交回复
热议问题