public void Publish(string eventTopic, object sender, ObjectEventArgs eventData) { if (!_eventMap.ContainsKey(eventTopic)) { return; } List<WeakReference<Action<object, ObjectEventArgs>>> deadRefs = null; foreach (WeakReference<Action<object, ObjectEventArgs>> weakRef in _eventMap[eventTopic]) { Action<object, ObjectEventArgs> action; if (weakRef.TryGetTarget(out action)) { action.Invoke(sender, eventData); } else { if (deadRefs == null) { deadRefs = new List<WeakReference<Action<object, ObjectEventArgs>>>(); } deadRefs.Add(weakRef); } } if (deadRefs == null) { return; } var deadIds = new List<string>(); foreach (var key in _actionMap.Keys) { if (deadRefs.Contains(_actionMap[key])) { deadIds.Add(key); } } foreach (var id in deadIds) { unsubscribe(id); } }
public void AddCount2(object sender, ObjectEventArgs e) { _count = _count + ((int) e.Value); label2.InvokeIfRequired(c => { c.Text = _count.ToString(); }); }