There is a class that is inherited from the IJob interface. An instance of this class is created by implementation of the interface. In the constructor of this class, I call a method to for quartz start ExecuteTimeBuilder.Start();
public class CalculateManager : ICalculateManager, IJob
{
private readonly IStrongDataRepository _strongDataRepository;
public CalculateManager(IStrongDataRepository strongDataRepository)
{
_strongDataRepository = strongDataRepository;
ExecuteTimeBuilder.Start();
}
public async Task Execute(IJobExecutionContext context)
{
Console.WriteLine("HelloJob is executing.");
}
Method .Start()
public static async void Start()
{
IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler();
await scheduler.Start();
IJobDetail job = JobBuilder.Create<CalculateManager>()
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(10)
.RepeatForever())
.Build();
await scheduler.ScheduleJob(job, trigger);
}
The Execute method just doesn't start work. This is console application .Core 3.0 Interfaces are registered in the custom StartUp class
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging();
services.AddSingleton<IConfigurationRoot>(Configuration);
services.AddSingleton<IStrongDataRepository, StrongDataRepository>();
services.AddSingleton<ICalculateManager, CalculateManager>();
services.AddDbContext<ApplicationDBContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
Why my method Task Execute(IJobExecutionContext context) doesn't show signs of life. It doesn't call.
It is not working cuz I call it on another instatnce where the consctructor is empty. I need a reflection and call my method in other instatce. It is work
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.