/// <summary> /// 删除一个消息接收器 /// </summary> /// <param name="listener">要删除的消息接收器</param> /// <returns></returns> public static bool Remove(Listener listener) { lock (NeedRemoveListeners) { if (!Contains(listener)) return false; NeedRemoveListeners.Add(listener); return true; } }
/// <summary> /// 添加一个消息接收器 /// </summary> /// <param name="listener">要添加的消息接收器</param> /// <returns></returns> public static bool Add(Listener listener) { lock (NeedAddListeners) { if (Contains(listener)) return false; NeedAddListeners.Add(listener); return true; } }
/// <summary> /// 确定指定的消息接收器是否已经被添加 /// </summary> /// <param name="listener">目标消息接收器</param> /// <returns></returns> public static bool Contains(Listener listener) { lock (NeedRemoveListeners) { lock (NeedAddListeners) { lock (Listeners) { return Listeners.Contains(listener) || NeedAddListeners.Contains(listener) || NeedRemoveListeners.Contains(listener); } } } }