예제 #1
0
 // Called from MeterListener.EnableMeasurementEvents
 internal void EnableMeasurement(ListenerSubscription subscription)
 {
     while (!_subscriptions.AddIfNotExist(subscription, (s1, s2) => object.ReferenceEquals(s1.Listener, s2.Listener)))
     {
         ListenerSubscription oldSubscription = _subscriptions.Remove(subscription, (s1, s2) => object.ReferenceEquals(s1.Listener, s2.Listener));
         if (object.ReferenceEquals(oldSubscription.Listener, subscription.Listener))
         {
             oldSubscription.Listener.MeasurementsCompleted?.Invoke(this, oldSubscription.State);
         }
     }
 }
예제 #2
0
        // Called from MeterListener.EnableMeasurementEvents
        internal object?EnableMeasurement(ListenerSubscription subscription, out bool oldStateStored)
        {
            oldStateStored = false;

            if (!_subscriptions.AddIfNotExist(subscription, (s1, s2) => object.ReferenceEquals(s1.Listener, s2.Listener)))
            {
                ListenerSubscription oldSubscription = _subscriptions.Remove(subscription, (s1, s2) => object.ReferenceEquals(s1.Listener, s2.Listener));
                _subscriptions.AddIfNotExist(subscription, (s1, s2) => object.ReferenceEquals(s1.Listener, s2.Listener));
                oldStateStored = object.ReferenceEquals(oldSubscription.Listener, subscription.Listener);
                return(oldSubscription.State);
            }

            return(false);
        }