我使用 Quartz.net 来安排一些任务。问题是它只能在本地调试时工作。
该代码也不适用于我的本地服务器和生产。
请不要将其标记为重复,因为其他问题中提到的解决方案都没有解决我的问题。
public class JobScheduler
{
public static ISchedulerFactory schedFact;
public static IScheduler sched;
public static void Start()
{
schedFact = new StdSchedulerFactory();
// get a scheduler
sched = schedFact.GetScheduler();
sched.Start();
IJobDetail job = JobBuilder.Create<RemovePlanJob>().Build();
int hours = Convert.ToInt32(System.Web.Configuration.WebConfigurationManager.AppSettings["schedulerHours"].ToString());
int minute = Convert.ToInt32(System.Web.Configuration.WebConfigurationManager.AppSettings["schedulerMinutes"].ToString());
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(hours, minute))
)
.Build();
sched.ScheduleJob(job, trigger);
}
}
public class RemovePlanJob : IJob
{
public void Execute(IJobExecutionContext context)
{
//execute code
}
}
任何帮助都会很棒!