private void EasyCL_Completed(object sender, string JobID) { InvokeEnded?.Invoke(this, EventArgs.Empty); if (JobID != null && CompletionLocks.ContainsKey(JobID)) { CompletionLocks[JobID].Set(); } }
public void Raise(object sender, TEventArgs e) { InvokeStarted?.Invoke(this, null); lock (_handlers) { _handlers.RemoveAll(h => !h.Invoke(sender, e)); } InvokeEnded?.Invoke(this, null); }
public void RaiseAsync(object sender, TEventArgs e, Predicate <object> filter) { InvokeStarted?.Invoke(sender, e as System.EventArgs); var asyncRaise = new Task <List <WeakDelegate> >(() => { var result = new List <WeakDelegate>(); var handlerCopy = new List <WeakDelegate>(_handlers); // Local copy to play around with. foreach (var handler in handlerCopy) { if (filter != null) { if (!filter(handler.GetTargetInstance())) { continue; } } try { if (!handler.Invoke(sender, e)) { result.Add(handler); } } catch (Exception ex) { AsyncRaiseFailed?.Invoke(sender, new EventFailedEventArgs(e as System.EventArgs, ex)); } } return(result); }); asyncRaise.ContinueWith((delegate(Task <List <WeakDelegate> > task) { lock (_handlers) { _handlers.RemoveAll(x => task.Result.Contains(x)); } InvokeEnded?.Invoke(sender, e as System.EventArgs); })); asyncRaise.Start(); }