Example #1
0
        /// <summary>Adds the counter to the set that the EventSource will report on.</summary>
        /// <remarks>
        /// Must only be invoked once, and only after the instance has been fully initialized.
        /// This should be invoked by a derived type's ctor as the last thing it does.
        /// </remarks>
        private protected void Publish()
        {
            Debug.Assert(_group is null);
            Debug.Assert(Name != null);
            Debug.Assert(EventSource != null);

            _group = CounterGroup.GetCounterGroup(EventSource);
            _group.Add(this);
        }
Example #2
0
 internal static CounterGroup GetCounterGroup(EventSource eventSource)
 {
     lock (s_counterGroupLock)
     {
         int eventSourceIndex = EventListener.EventSourceIndex(eventSource);
         EnsureEventSourceIndexAvailable(eventSourceIndex);
         Debug.Assert(s_counterGroups != null);
         WeakReference <CounterGroup> weakRef = CounterGroup.s_counterGroups[eventSourceIndex];
         if (weakRef == null || !weakRef.TryGetTarget(out CounterGroup? ret))
         {
             ret = new CounterGroup(eventSource);
             CounterGroup.s_counterGroups[eventSourceIndex] = new WeakReference <CounterGroup>(ret);
         }
         return(ret);
     }
 }