private static void LazyCreatePerformanceCounter(PerformanceCounterHolder holder, TelemetryData data)
        {
            if (holder.Counter != null)
            {
                return;
            }

            // If counter does not exist then it's probably an installation problem:
            // * counters have not been created and TelemetrySession.Start did it but OS didn't refresh them yet;
            // * category already existed but a new version added more counters and old category has not been properly uninstalled.
            if (!PerformanceCounterCategory.CounterExists(data.Name, data.Category))
            {
                holder.IsDisabled = true;
                return;
            }

            holder.Counter = new PerformanceCounter(data.Category, data.Name, false);

            if (data.CounterType == TelemetryDataType.AverageCount)
            {
                // Base PC name convention: keep in sync with code in WpcTelemetrySessionInstaller
                holder.Base = new PerformanceCounter(data.Category, data.Name + "Base", false);

                holder.Counter.RawValue = 0;
                holder.Base.RawValue    = 0;
            }
        }
        public bool TryGetValue(TelemetryData data, out PerformanceCounterHolder value)
        {
            if (!_telemetryData.TryGetValue(data, out value))
            {
                return(false);
            }

            // PerformanceCounterHolder exists but it's disabled, there is no need to
            // (try to) create an instance of its associated PC(s).
            if (value.IsDisabled)
            {
                return(true);
            }

            // If caller requested this PerformanceCounterHolder then it will use it,
            // it's the right moment to (lazy) create required instances. Note that
            // in this way performance penality for this operation is spanned across program
            // execution, it's a drawback but it speed-up initialization time (especially if there are
            // many mostly unused PCs).
            LazyCreatePerformanceCounter(value, data);

            return(true);
        }