Esempio n. 1
0
 /// <summary>
 /// 加载Job
 /// </summary>
 public static void LoadJobs()
 {
     foreach (var an in HangfireJobs.GroupBy(c => c.AssemblyName))
     {
         Assembly assembly = Assembly.Load(new AssemblyName(an.Key));
         foreach (var t in an)
         {
             Type type = assembly.GetType(t.ClassName);
             var  task = JobActivator.Current.ActivateJob(type) as IJob;
             if (task == null)
             {
                 continue;
             }
             if (t.Enable)
             {
                 RecurringJob.AddOrUpdate(t.JobName, () => task.Run(), t.Cron, timeZone: TimeZoneInfo.Local);
             }
             else
             {
                 RecurringJob.RemoveIfExists(t.JobName);
             }
         }
     }
 }