public static void jobCallback(object state) { WebJob job = (WebJob)state; Timer mytimer = timers[job]; mytimer.Change(Timeout.Infinite, job.Interval); IWebJobItem obj = ObjectContext.GetByType(job.Type) as IWebJobItem; if (obj == null) { logger.Info("job[" + job.Name + "] type does not exists:" + job.Type); return; } try { obj.Execute(); } catch (Exception ex) { logger.Error(ex.Message + Environment.NewLine + ex.StackTrace); } finally { obj.End(); DbContext.closeConnectionAll(); mytimer.Change(job.Interval, job.Interval); } }
private static void startJob() { IList jobs = new WebJob().findAll(); if (jobs != null && jobs.Count > 0) { foreach (WebJob job in jobs) { if (job.Interval <= 0) { logger.Warn("job is invalid, name:" + job.Name + ", type:" + job.Type + ", interval:" + job.Interval); continue; } if (job.IsRunning == false) continue; timers.Add(job, new Timer(new TimerCallback(jobCallback), job, job.Interval, job.Interval)); } } }
private static void startJob() { IList jobs = new WebJob().findAll(); if (jobs != null && jobs.Count > 0) { foreach (WebJob job in jobs) { if (job.Interval <= 0) { logger.Warn("job is invalid, name:" + job.Name + ", type:" + job.Type + ", interval:" + job.Interval); continue; } if (job.IsRunning == false) { continue; } timers.Add(job, new Timer(new TimerCallback(jobCallback), job, job.Interval, job.Interval)); } } }