public void UnSubscribeEvent(string eventName, EventProcessHandler handler) { lock (this) { Delegate handlerList = (Delegate)this.htableSubscribed[eventName]; if (handlerList != null) { handlerList = Delegate.Remove(handlerList, handler); this.htableSubscribed[eventName] = handlerList; } } }
//handler是本地委托 public void SubscribeEvent(string eventName, EventProcessHandler handler) { lock (this) { Delegate handlerList = (Delegate)this.htableSubscribed[eventName]; if (handlerList == null) { this.htableSubscribed.Add(eventName, handler); this.eventServer.SubscribeEvent(eventName, new EventProcessHandler(this.OnRemoteEventHappen)); return; } handlerList = Delegate.Combine(handlerList, handler); this.htableSubscribed[eventName] = handlerList; } }