private void SchedulerCallback(object sender) { try { if (ConfigGlobal_Arsenal.SchedulerActive) { var declaringType = MethodBase.GetCurrentMethod().DeclaringType; if (declaringType != null) { var assembly = declaringType.Assembly.GetName().Name; ScheduleManager.Execute(assembly); } } } catch (Exception ex) { ILog log = new AppLog(); log.Warn(ex, new LogInfo { MethodInstance = MethodBase.GetCurrentMethod(), ThreadInstance = Thread.CurrentThread }); } }
private void SchedulerCallback(object sender) { try { if (ConfigGlobal.SchedulerActive) { ScheduleManager.Execute(); } } catch (Exception ex) { ILog log = new AppLog(); log.Warn(ex, new LogInfo { MethodInstance = MethodBase.GetCurrentMethod(), ThreadInstance = Thread.CurrentThread }); } }
protected void gvSchedule_SelectedIndexChanged(object sender, EventArgs e) { ILog log = new AppLog(); var logInfo = new LogInfo { MethodInstance = MethodBase.GetCurrentMethod(), ThreadInstance = Thread.CurrentThread }; try { if (gvSchedule.SelectedIndex != -1) { var key = gvSchedule.DataKeys[gvSchedule.SelectedIndex].Value.ToString(); var s = Schedule.Single(key); var instance = s.IScheduleInstance; ManagedThreadPool.QueueUserWorkItem(instance.Execute); s.LastCompletedTime = DateTime.Now; s.Update(); log.Info($"ISchedule Manually: {s.ScheduleType}", logInfo); //this.ClientScript.RegisterClientScriptBlock(typeof(string), "success", string.Format("任务:{0}执行成功');", s.ScheduleType), true); } } catch (Exception ex) { log.Error(ex, logInfo); //this.ClientScript.RegisterClientScriptBlock(typeof(string), "failed", string.Format("alert('{0}');", ex.Message.ToString()), true); } finally { //BindData(); } }
public static void Execute(string assembly = null) { ILog log = new AppLog(); var logInfo = new LogInfo { MethodInstance = MethodBase.GetCurrentMethod(), ThreadInstance = Thread.CurrentThread }; try { // The application must run schedule task by it's own assembly name var list = !string.IsNullOrEmpty(assembly) ? Schedule.All().FindAll(x => x.IsActive && x.ScheduleType.Contains(assembly)) : Schedule.All().FindAll(x => x.IsActive); if (list.Count > 0) { foreach (var s in list) { if (s.ShouldExecute()) { // Call this method BEFORE processing the ScheduledEvent. This will help protect against long running events // being fired multiple times. Note, it is not absolute protection. App restarts will cause events to look like // they were completed, even if they were not. Again, ScheduledEvents are helpful...but not 100% reliable var instance = s.IScheduleInstance; ManagedThreadPool.QueueUserWorkItem(instance.Execute); s.LastCompletedTime = DateTime.Now; s.Update(); log.Debug($"ISchedule: {s.ScheduleType}", logInfo); } } } } catch (Exception ex) { log.Debug(ex, logInfo); throw; } }