Пример #1
0
 private static void AddJobs()
 {
     SpareTime.Do("*/1 * * * *", (timer, count) =>
     {
         Scoped.Create((_, scope) =>
         {
             var services    = scope.ServiceProvider;
             var taskService = services.GetService <ITimedReminderJob>();
             $"Job Begin[{count}]-----------------------".LogInformation <Startup>();
             taskService.Do().Wait();
             $"Job End[{count}]-------------------------".LogInformation <Startup>();
         });
     }, "SyncSequence", "定时同步MES工序");
 }
Пример #2
0
 public void ExecSql(SpareTimer timer, long count)
 {
     //创建作用域
     Scoped.Create((factory, scope) =>
     {
         var start = DateTime.Now;
         Console.WriteLine(start.ToString("yyyy-MM-dd HH:mm:ss") + ":任务开始-----------");
         var services = scope.ServiceProvider;
         // 数据库操作
         var db = Db.GetSqlRepository(services);
         if (!string.IsNullOrEmpty(timer.Description)) //假设 后台任务 中把 sql 语句写到了备注里面
         {
             db.SqlNonQuery(timer.Description);
         }
         var end = DateTime.Now;
         Console.WriteLine(end.ToString("yyyy-MM-dd HH:mm:ss") + ":任务结束-----------");
         Console.WriteLine($"SQL执行了:{count} 次,耗时:{(end - start).TotalMilliseconds}ms");
     });
 }