I am trying to run several jobs with Quartz.NET and Topshelf using C #.
HostFactory.Run(c => { c.ScheduleQuartzJobAsService(q => q.WithJob(() => JobBuilder.Create<TypeA>().Build()) .AddTrigger(() => TriggerBuilder.Create().WithSimpleSchedule(builder => builder.WithIntervalInSeconds(ConfigurationSettings.AppFrequencyInSeconds).RepeatForever()).Build()) ).StartAutomatically(). ScheduleQuartzJobAsService(r => r.WithJob(() => JobBuilder.Create<TypeB>().Build()) .AddTrigger(() => TriggerBuilder.Create().WithSimpleSchedule(builder => builder. WithIntervalInSeconds(ConfigurationSettings.AppFrequencyInSeconds).RepeatForever()).Build()) ).StartAutomatically(); c.StartAutomatically(); c.SetServiceName("ServiceName"); });
Using the code above, only the execute method in TypeB is executed. I also tried:
HostFactory.Run(c => { c.ScheduleQuartzJobAsService(q => q.WithJob(() => JobBuilder.Create<TypeA>().Build()) .AddTrigger(() => TriggerBuilder.Create().WithSimpleSchedule(builder => builder. WithIntervalInSeconds(ConfigurationSettings.AppFrequencyInSeconds).RepeatForever()).Build()) ).StartAutomatically(); c.StartAutomatically(); c.SetServiceName("Service1"); c.ScheduleQuartzJobAsService(r => r.WithJob(() => JobBuilder.Create<TypeB>().Build()) .AddTrigger(() => TriggerBuilder.Create().WithSimpleSchedule(builder => builder. WithIntervalInSeconds(ConfigurationSettings.AppFrequencyInSeconds).RepeatForever()).Build()) ).StartAutomatically(); c.StartAutomatically(); c.SetServiceName("Service2"); });
With this code, only the execute method in TypeB is called. Both of my TypeA and TypeB classes have βExecuteβ methods, which are the entry points for each class (which are called if they are part of the job on their own). It seems that whatever service code is second, it is the one that is always called - if I replace the order of these two calls to the ScheduleQuartzJobAsService, it is always a class in the second call made.
How can I write my HostFactory.Run method so that both jobs run simultaneously?
source share