1
我是Topshelf和Quartz.net的新手。C#Quartz.net調度程序作爲Windows服務不能執行雖然窗口服務正在運行
我想運行一個使用c#quartz.net的調度程序作爲Windows服務。我創建了一個Windows服務並執行了所有必要的設置來調用調度程序作業。我沒有收到任何錯誤,並且窗口服務已成功啓動。但是,當我將調試點放在調度程序作業中時,即使設置時間已到,它也不會執行。
的Program.cs
internal class Program
{
private static readonly IUnityContainer Container = UnityConfig.GetConfiguredContainer();
static void Main(string[] args)
{
HostFactory.Run(serviceConfig =>
{
serviceConfig.Service<ISchedulerService>(serviceInstance =>
{
serviceInstance.ConstructUsing(name => Container.Resolve<ISchedulerService>());
serviceInstance.WhenStarted(execute => execute.Start());
serviceInstance.WhenStopped(execute => execute.Stop());
});
serviceConfig.RunAsLocalSystem();
serviceConfig.SetDescription("Scheduler");
serviceConfig.SetDisplayName("Scheduler");
serviceConfig.SetServiceName("Scheduler");
serviceConfig.StartAutomatically();
});
}
}
ScheduleService.cs
public class SchedulerService : ISchedulerService
{
private readonly IScheduler _scheduler;
private readonly DateTimeOffset _startTime = new DateTimeOffset(new DateTime(2016, 05, 01, 08, 30, 00, DateTimeKind.Utc).ToLocalTime());
public SchedulerService(IScheduler scheduler)
{
_scheduler = scheduler;
}
public void Start()
{
StartScheduledJobs();
}
public void Stop()
{
_scheduler.Shutdown(true);
}
private void StartScheduledJobs()
{
try
{
SchedulePrsReportExportJob();
_scheduler.Start();
}
catch (Exception ex)
{
}
}
private void SchedulePrsReportExportJob()
{
var jobDetail = JobBuilder.Create<MyJob>()
.WithIdentity("job1", "group1")
.Build();
var trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
//.WithSchedule(CronScheduleBuilder.CronSchedule("0 1 0 ? * *")) //minute past midnight everyday
//.StartAt(_startTime)
//.WithSchedule(CronScheduleBuilder.CronSchedule("0 0/5 * ? * *")) //minute past midnight everyday
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(16, 18))
.StartNow()
.Build();
_scheduler.ScheduleJob(jobDetail, trigger);
}
}
工作
public class MyJob : IJob
{
private readonly ISomeService _service;
public ExportPrsLiveReportJob(ILogProvider logProvider, ISomeService service)
{
_service = service;
}
public async void Execute(IJobExecutionContext context)
{
var data = await _service.Get();
}
}
誰能幫我我在做什麼錯在這裏?
謝謝
你有沒有得到這個解決方案?我也有同樣的問題。 – Remotec
@RemotecUk,不,我沒有得到任何解決方案。 –