diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs index 1a210a05cb03..0fb88950391e 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs @@ -92,24 +92,6 @@ private EventRegistrationToken AddEventHandlerNoLock(T handler) return token; } - // 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; - } - // Generate a token that may be used for a particular event handler. We will frequently be called // upon to look up a token value given only a delegate to start from. Therefore, we want to make // an initial token value that is easily determined using only the delegate instance itself. Although @@ -169,6 +151,23 @@ private static EventRegistrationToken GetPreferredToken(T handler) return new EventRegistrationToken(tokenValue); } + // 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, out T handler) + { + lock (m_tokens) + { + if (m_tokens.TryGetValue(token, out handler)) + { + RemoveEventHandlerNoLock(token); + return true; + } + } + + return false; + } + public void RemoveEventHandler(EventRegistrationToken token) { // The 0 token is assigned to null handlers, so there's nothing to do