public static PdhCounter AddCounter(this PdhQueryHandle query, string category, string counter, string instance, bool throwOnError)
        {
            var path = instance == null
                ? CounterPathFactory.Create(category, counter)
                : CounterPathFactory.Create(category, counter, instance);

            var status = PdhExports.PdhAddEnglishCounter(query, path, IntPtr.Zero, out var pdhCounter);

            if (status == PdhStatus.PDH_CSTATUS_VALID_DATA)
            {
                return(pdhCounter);
            }

            if (!throwOnError)
            {
                return(default);
Beispiel #2
0
 protected override bool ReleaseHandle() =>
 PdhExports.PdhCloseQuery(handle) == PdhStatus.PDH_CSTATUS_VALID_DATA;
Beispiel #3
0
 public static PdhQueryHandle OpenRealtime()
 {
     PdhExports.PdhOpenQuery(null, IntPtr.Zero, out var handle).EnsureSuccess(nameof(PdhExports.PdhOpenQuery));
     return(handle);
 }
 public static PdhStatus CollectQueryData(this PdhQueryHandle query)
 => PdhExports.PdhCollectQueryData(query);