Create Schedule Job
1. use NuGet to install Quartz to Project
2. Create sub class of IJob:
public class HelpOnlineJob : IJob
{
public void Execute(IJobExecutionContext context)
{
// call methods in schedule
new CompanyDB().ResetPrintingTimes();
new ASIMSNotificationDB().ResetReachingPrintingAllowanceNotification();
new OnlineEducationDB().BackupDatabase();
}
}
3. Create class with static method
public class HelpOnlineJobScheduler
{
public static void Start()
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<HelpOnlineJob>().Build();
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0,0))
).Build();
scheduler.ScheduleJob(job, trigger);
}
}
4. In Startup class:
public class Startup
{
public void Configuration(IAppBuilder app)
{
// call this start method
HelpOnlineJobScheduler.Start();
}
}
2. Create sub class of IJob:
public class HelpOnlineJob : IJob
{
public void Execute(IJobExecutionContext context)
{
// call methods in schedule
new CompanyDB().ResetPrintingTimes();
new ASIMSNotificationDB().ResetReachingPrintingAllowanceNotification();
new OnlineEducationDB().BackupDatabase();
}
}
3. Create class with static method
public class HelpOnlineJobScheduler
{
public static void Start()
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<HelpOnlineJob>().Build();
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0,0))
).Build();
scheduler.ScheduleJob(job, trigger);
}
}
4. In Startup class:
public class Startup
{
public void Configuration(IAppBuilder app)
{
// call this start method
HelpOnlineJobScheduler.Start();
}
}
Comments
Post a Comment