public void RemoveEventHandler(EventRegistrationToken token) { if ((long)token.Value == 0L) { return; } lock (this.m_tokens) this.RemoveEventHandlerNoLock(token); }
// void PropertyChanged.remove(EventRegistrationToken token) private void remove_CanExecuteChanged(EventRegistrationToken token) { ICommand _this = Unsafe.As <ICommand>(this); EventRegistrationTokenTable <EventHandler> table = s_weakTable.GetOrCreateValue(_this); if (table.RemoveEventHandler(token, out EventHandler handler)) { _this.CanExecuteChanged -= handler; } }
// void PropertyChanged.remove(EventRegistrationToken token) internal void remove_PropertyChanged(EventRegistrationToken token) { INotifyPropertyChanged _this = Unsafe.As <INotifyPropertyChanged>(this); EventRegistrationTokenTable <PropertyChangedEventHandler> table = s_weakTable.GetOrCreateValue(_this); if (table.RemoveEventHandler(token, out PropertyChangedEventHandler handler)) { _this.PropertyChanged -= handler; } }
// EventRegistrationToken PropertyChanged.add(PropertyChangedEventHandler value) internal EventRegistrationToken add_PropertyChanged(PropertyChangedEventHandler value) { INotifyPropertyChanged _this = Unsafe.As<INotifyPropertyChanged>(this); EventRegistrationTokenTable<PropertyChangedEventHandler> table = s_weakTable.GetOrCreateValue(_this); EventRegistrationToken token = table.AddEventHandler(value); _this.PropertyChanged += value; return token; }
private void RemoveEventHandlerNoLock(EventRegistrationToken token) { T obj; if (!this.m_tokens.TryGetValue(token, out obj)) { return; } this.m_tokens.Remove(token); this.m_invokeList = (T)Delegate.Remove((Delegate)(object)this.m_invokeList, (Delegate)(object)obj); }
// EventRegistrationToken PropertyChanged.add(EventHandler<object> value) private EventRegistrationToken add_CanExecuteChanged(EventHandler<object> value) { ICommand _this = Unsafe.As<ICommand>(this); EventRegistrationTokenTable<EventHandler> table = s_weakTable.GetOrCreateValue(_this); EventHandler handler = ICommandAdapterHelpers.CreateWrapperHandler(value); EventRegistrationToken token = table.AddEventHandler(handler); _this.CanExecuteChanged += handler; return token; }
internal EventRegistrationToken add_CollectionChanged(NotifyCollectionChangedEventHandler value) { INotifyCollectionChanged _this = JitHelpers.UnsafeCast <INotifyCollectionChanged>(this); EventRegistrationTokenTable <NotifyCollectionChangedEventHandler> table = m_weakTable.GetOrCreateValue(_this); EventRegistrationToken token = table.AddEventHandler(value); _this.CollectionChanged += value; return(token); }
public bool Push(EventRegistrationToken token) { bool flag = false; if (this.restTokens == null) { this.restTokens = new List <EventRegistrationToken>(); flag = true; } this.restTokens.Add(token); return(flag); }
private void RemoveEventHandlerNoLock(EventRegistrationToken token) { if (m_tokens.TryGetValue(token, out T? handler)) { m_tokens.Remove(token); // Update the current invocation list to remove the delegate Delegate?invokeList = (Delegate?)(object?)m_invokeList; invokeList = MulticastDelegate.Remove(invokeList, (Delegate?)(object?)handler); m_invokeList = (T?)(object?)invokeList; } }
private EventRegistrationToken AddEventHandlerNoLock(T handler) { EventRegistrationToken key = EventRegistrationTokenTable <T> .GetPreferredToken(handler); while (this.m_tokens.ContainsKey(key)) { key = new EventRegistrationToken(key.Value + 1UL); } this.m_tokens[key] = handler; this.m_invokeList = (T)Delegate.Combine((Delegate)(object)this.m_invokeList, (Delegate)(object)handler); return(key); }
internal void remove_PropertyChanged(EventRegistrationToken token) { INotifyPropertyChanged _this = JitHelpers.UnsafeCast <INotifyPropertyChanged>(this); EventRegistrationTokenTable <PropertyChangedEventHandler> table = m_weakTable.GetOrCreateValue(_this); PropertyChangedEventHandler handler = table.ExtractHandler(token); if (handler != null) { _this.PropertyChanged -= handler; } }
// Token: 0x06006363 RID: 25443 RVA: 0x00151F30 File Offset: 0x00150130 private void RemoveEventHandlerNoLock(EventRegistrationToken token) { T t; if (this.m_tokens.TryGetValue(token, out t)) { this.m_tokens.Remove(token); Delegate @delegate = (Delegate)((object)this.m_invokeList); @delegate = Delegate.Remove(@delegate, (Delegate)((object)t)); this.m_invokeList = (T)((object)@delegate); } }
// void PropertyChanged.remove(EventRegistrationToken token) private void remove_CanExecuteChanged(EventRegistrationToken token) { ICommand _this = JitHelpers.UnsafeCast <ICommand>(this); EventRegistrationTokenTable <EventHandler> table = m_weakTable.GetOrCreateValue(_this); EventHandler handler = table.ExtractHandler(token); if (handler != null) { _this.CanExecuteChanged -= handler; } }
// void CollectionChanged.remove(EventRegistrationToken token) internal void remove_CollectionChanged(EventRegistrationToken token) { INotifyCollectionChanged _this = Unsafe.As <INotifyCollectionChanged>(this); EventRegistrationTokenTable <NotifyCollectionChangedEventHandler> table = s_weakTable.GetOrCreateValue(_this); NotifyCollectionChangedEventHandler handler = table.ExtractHandler(token); if (handler != null) { _this.CollectionChanged -= handler; } }
// Remove the event handler from the table and // Get the delegate associated with an event registration token if it exists // If the event registration token is not registered, returns false public bool RemoveEventHandler(EventRegistrationToken token, [NotNullWhen(true)] out T?handler) { lock (m_tokens) { if (m_tokens.TryGetValue(token, out handler)) { RemoveEventHandlerNoLock(token); return(true); } } return(false); }
internal T ExtractHandler(EventRegistrationToken token) { T obj = default(T); lock (this.m_tokens) { if (this.m_tokens.TryGetValue(token, out obj)) { this.RemoveEventHandlerNoLock(token); } } return(obj); }
public bool Pop(out EventRegistrationToken token) { if (this.restTokens == null || this.restTokens.Count == 0) { token = this.firstToken; return(false); } int index = this.restTokens.Count - 1; token = this.restTokens[index]; this.restTokens.RemoveAt(index); return(true); }
public void RemoveEventHandler(EventRegistrationToken token) { // The 0 token is assigned to null handlers, so there's nothing to do if (token.Value == 0) { return; } lock (m_tokens) { RemoveEventHandlerNoLock(token); } }
public void RemoveEventHandler(EventRegistrationToken token) { if (token.Value == 0UL) { return; } Dictionary <EventRegistrationToken, T> tokens = this.m_tokens; lock (tokens) { this.RemoveEventHandlerNoLock(token); } }
// Push a new token into this list // Returns true if you need to copy back this list into the dictionary (so that you // don't lose change outside the dictionary). false otherwise. public bool Push(EventRegistrationToken token) { bool needCopy = false; if (restTokens == null) { restTokens = new System.Collections.Generic.Internal.List <EventRegistrationToken>(); needCopy = true; } restTokens.Add(token); return(needCopy); }
// Get the delegate associated with an event registration token if it exists. Additionally, // remove the registration from the table at the same time. If the token is not registered, // Extract returns null and does not modify the table. // [System.Runtime.CompilerServices.FriendAccessAllowed] internal T ExtractHandler(EventRegistrationToken token) { T handler = null; lock (m_tokens) { if (m_tokens.TryGetValue(token, out handler)) { RemoveEventHandlerNoLock(token); } } return(handler); }
internal T ExtractHandler(EventRegistrationToken token) { T result = default(T); Dictionary <EventRegistrationToken, T> tokens = this.m_tokens; lock (tokens) { if (this.m_tokens.TryGetValue(token, out result)) { this.RemoveEventHandlerNoLock(token); } } return(result); }
// Token: 0x0600635E RID: 25438 RVA: 0x00151CD4 File Offset: 0x0014FED4 private EventRegistrationToken AddEventHandlerNoLock(T handler) { EventRegistrationToken preferredToken = EventRegistrationTokenTable <T> .GetPreferredToken(handler); while (this.m_tokens.ContainsKey(preferredToken)) { preferredToken = new EventRegistrationToken(preferredToken.Value + 1UL); } this.m_tokens[preferredToken] = handler; Delegate @delegate = (Delegate)((object)this.m_invokeList); @delegate = Delegate.Combine(@delegate, (Delegate)((object)handler)); this.m_invokeList = (T)((object)@delegate); return(preferredToken); }
// Pops the last token // Returns false if no more tokens left, true otherwise public bool Pop(out EventRegistrationToken token) { // Only 1 token in this list and we just removed the last token if (restTokens == null || restTokens.Count == 0) { token = firstToken; return(false); } int last = restTokens.Count - 1; token = restTokens[last]; restTokens.RemoveAt(last); return(true); }
internal static void AddEventHandler <T>(Func <T, EventRegistrationToken> addMethod, Action <EventRegistrationToken> removeMethod, T handler) { Debug.Assert(addMethod != null); Debug.Assert(removeMethod != null); // Add the method, and make a note of the token -> delegate mapping. object instance = removeMethod.Target; #if !RHTESTCL Debug.Assert(instance != null && !(instance is __ComObject)); #endif System.Collections.Generic.Internal.Dictionary <object, EventRegistrationTokenList> registrationTokens = GetEventRegistrationTokenTable(instance, removeMethod); EventRegistrationToken token = addMethod(handler); try { registrationTokens.LockAcquire(); EventRegistrationTokenList tokens; if (!registrationTokens.TryGetValue(handler, out tokens)) { tokens = new EventRegistrationTokenList(token); registrationTokens[handler] = tokens; } else { bool needCopy = tokens.Push(token); // You need to copy back this list into the dictionary (so that you don't lose change outside dictionary) if (needCopy) { registrationTokens[handler] = tokens; } } #if false BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event subscribed for managed instance = " + instance + ", handler = " + handler + "\n"); #endif } finally { registrationTokens.LockRelease(); } }
public void RemoveEventHandler(T handler) { // To match the Windows Runtime behaivor when adding a null handler, removing one is a no-op if (handler == null) { return; } lock (m_tokens) { // Fast path - if the delegate is stored with its preferred token, then there's no need to do // a full search of the table for it. Note that even if we find something stored using the // preferred token value, it's possible we have a collision and another delegate was using that // value. Therefore we need to make sure we really have the handler we want before taking the // fast path. EventRegistrationToken preferredToken = GetPreferredToken(handler); T registeredHandler; if (m_tokens.TryGetValue(preferredToken, out registeredHandler)) { if (registeredHandler == handler) { RemoveEventHandlerNoLock(preferredToken); return; } } // Slow path - we didn't find the delegate with its preferred token, so we need to fall // back to a search of the table foreach (KeyValuePair <EventRegistrationToken, T> registration in m_tokens) { if (registration.Value == (T)(object)handler) { RemoveEventHandlerNoLock(registration.Key); // If a delegate has been added multiple times to handle an event, then it // needs to be removed the same number of times to stop handling the event. // Stop after the first one we find. return; } } // Note that falling off the end of the loop is not an error, as removing a registration // for a handler that is not currently registered is simply a no-op } }
internal static void AddEventHandler <T>(Func <T, EventRegistrationToken> addMethod, Action <EventRegistrationToken> removeMethod, T handler) { object instanceKey = WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.GetInstanceKey(removeMethod); EventRegistrationToken token = addMethod(handler); bool flag = false; try { WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.s_eventCacheRWLock.AcquireReaderLock(-1); try { WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.TokenListCount tokenListCount; ConditionalWeakTable <object, WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount> registrationTokenTable = WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.GetOrCreateEventRegistrationTokenTable(instanceKey, removeMethod, out tokenListCount); lock (registrationTokenTable) { WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount local_3; if (registrationTokenTable.FindEquivalentKeyUnsafe((object)handler, out local_3) == null) { local_3 = new WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount(tokenListCount, token); registrationTokenTable.Add((object)handler, local_3); } else { local_3.Push(token); } flag = true; } } finally { WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.s_eventCacheRWLock.ReleaseReaderLock(); } } catch (Exception ex) { if (!flag) { removeMethod(token); } throw; } }
private EventRegistrationToken AddEventHandlerNoLock(T handler) { Debug.Assert(handler != null); // Get a registration token, making sure that we haven't already used the value. This should be quite // rare, but in the case it does happen, just keep trying until we find one that's unused. EventRegistrationToken token = GetPreferredToken(handler); while (m_tokens.ContainsKey(token)) { token = new EventRegistrationToken(token.Value + 1); } m_tokens[token] = handler; // Update the current invocation list to include the newly added delegate Delegate invokeList = (Delegate)(object)m_invokeList; invokeList = MulticastDelegate.Combine(invokeList, (Delegate)(object)handler); m_invokeList = (T)(object)invokeList; return(token); }
internal static void AddEventHandler <T>(Func <T, EventRegistrationToken> addMethod, Action <EventRegistrationToken> removeMethod, T handler) { Dictionary <object, WindowsRuntimeMarshal.EventRegistrationTokenList> registrationTokenTable = WindowsRuntimeMarshal.ManagedEventRegistrationImpl.GetEventRegistrationTokenTable(removeMethod.Target, removeMethod); EventRegistrationToken token = addMethod(handler); lock (registrationTokenTable) { WindowsRuntimeMarshal.EventRegistrationTokenList local_4; if (!registrationTokenTable.TryGetValue((object)handler, out local_4)) { local_4 = new WindowsRuntimeMarshal.EventRegistrationTokenList(token); registrationTokenTable[(object)handler] = local_4; } else { if (!local_4.Push(token)) { return; } registrationTokenTable[(object)handler] = local_4; } } }
// void PropertyChanged.remove(EventRegistrationToken token) private void remove_CanExecuteChanged(EventRegistrationToken token) { ICommand _this = JitHelpers.UnsafeCast<ICommand>(this); EventRegistrationTokenTable<EventHandler> table = s_weakTable.GetOrCreateValue(_this); EventHandler handler = table.ExtractHandler(token); if (handler != null) { _this.CanExecuteChanged -= handler; } }
public bool Pop(out EventRegistrationToken token) { return(this._tokenList.Pop(out token)); }
// void PropertyChanged.remove(EventRegistrationToken token) internal void remove_PropertyChanged(EventRegistrationToken token) { INotifyPropertyChanged _this = JitHelpers.UnsafeCast<INotifyPropertyChanged>(this); EventRegistrationTokenTable<PropertyChangedEventHandler> table = s_weakTable.GetOrCreateValue(_this); PropertyChangedEventHandler handler = table.ExtractHandler(token); if (handler != null) { _this.PropertyChanged -= handler; } }