protected virtual void OnDispatch(DispatchEventArgs e) { if (Dispatch != null) { Dispatch(this, e); } }
// 可以供继承的类重写,以便继承类拒绝其他对象对它的监视 protected virtual void OnDispatch(DispatchEventArgs e) { if (Dispatch != null) // 如果有对象注册 { Dispatch(this, e); // 调用所有注册对象的方法 } }
public void dispacthEvent(int type, params object[] data) { if (EventTable.ContainsKey(type)) { DispatchEventArgs e = new DispatchEventArgs(type, data); List <DispatchEventHandler> funcArr = (List <DispatchEventHandler>)EventTable[type]; List <DispatchEventHandler> funcArrTemp = new List <DispatchEventHandler>(funcArr); foreach (DispatchEventHandler func in funcArrTemp) { this.Dispatch = func; OnDispatch(e); } } }
public void dispacthEvent(ValueType t, params object[] data) { int type = (int)t; if (EventTable.ContainsKey(type)) { DispatchEventArgs e = new DispatchEventArgs(type, data); List <DispatchEventHandler> funcArr = (List <DispatchEventHandler>)EventTable[type]; List <DispatchEventHandler> funcArrTemp = new List <DispatchEventHandler>(funcArr); int count = funcArrTemp.Count; for (int i = 0; i < count; i++) { this.Dispatch = funcArrTemp[i]; OnDispatch(e); } } }
public void HandleTaskEnd(object s, DispatchEventArgs e) { QueuedTasks.Remove(e.Task.ID); if (!e.Task.Recurring) { Tasks.Remove(e.Task); } if ((PuckCache.UpdateTaskLastRun && !e.Task.Recurring) || (PuckCache.UpdateRecurringTaskLastRun && e.Task.Recurring)) { var repo = PuckCache.PuckRepo; var taskMeta = repo.GetPuckMeta().Where(x => x.Name == DBNames.Tasks && x.ID == e.Task.ID).FirstOrDefault(); if (taskMeta != null) { taskMeta.Value = JsonConvert.SerializeObject(e.Task); repo.SaveChanges(); repo = null; } } }
public void HandleTaskEnd(object s, DispatchEventArgs e) { int removedId = 0; QueuedTasks.Remove(e.Task.ID, out removedId); if (!e.Task.Recurring) { Tasks.Remove(e.Task); } if ((PuckCache.UpdateTaskLastRun && !e.Task.Recurring) || (PuckCache.UpdateRecurringTaskLastRun && e.Task.Recurring)) { using (var scope = PuckCache.ServiceProvider.CreateScope()) { var repo = scope.ServiceProvider.GetService <I_Puck_Repository>(); var taskMeta = repo.GetPuckMeta().Where(x => x.Name == DBNames.Tasks && x.ID == e.Task.ID).FirstOrDefault(); if (taskMeta != null) { taskMeta.Value = JsonConvert.SerializeObject(e.Task); repo.SaveChanges(); repo = null; } } } }