I have a service:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class PremieraInteraction : ServiceInit, IPremieraInteraction
{
public PremieraInteraction()
{
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();
// construct job info
IJobDetail jobDetail = JobBuilder.Create<PremieraUpdate>().WithIdentity("PremieraUpdateJob").Build();
ITrigger trigger =
TriggerBuilder.Create().WithIdentity("PremieraUpdateTrigger").StartNow().WithSimpleSchedule(
x => x.WithIntervalInSeconds(10)).Build();
sched.ScheduleJob(jobDetail, trigger);
}
}
This is the job:
public class PremieraUpdate:IJob
{
public void Execute(IJobExecutionContext context)
{
Debug.WriteLine("Fire");
}
}
The problem is that it works only once. Why does the scheduler not repeat every 10 seconds?
I would suggest you to instantiate the factory and scheduler in the
Application_Startevent ofGlobal.asax.csand store them in static public properties.Now inside the service you can access the scheduler through the
Globalproperty.Ex.
I hope you are using the WCF service to schedule new jobs to the Quartz server that will be typically running in a windows service. Instead of scheduling the job in the constructor you can do that in a method that will take the details of the job and finally schedule and run it.
If you go with this implementation you don’t need to mark the service as singleton.