in this windows form app i use this Scheduler from Quartz.NET to trigger a job on certain time. Code works fine but i have an issue when executing the job and need to call something from the form outside the method created by the job. The (textBox1.Text) isnt inherited inside the method that is created on triggered job. (i think it has to do with the fact that Scheduler class is public async, any explanation is welcome)
namespace TaxControl
{
public partial class TaxControl : Form
{
.........................................
public class Scheduler
{
public async void Start()
{
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
IScheduler scheduler = await schedulerFactory.GetScheduler();
await scheduler.Start();
IJobDetail job = JobBuilder.Create<Job>()
.WithIdentity("job", "group1")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("job", "group1")
.WithCronSchedule("0 36 18 * * ?")
.Build();
await scheduler.ScheduleJob(job, trigger);
}
}
public class Job : IJob
{
Task IJob.Execute(IJobExecutionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
Task taskA = new Task(() => InfoControl());
taskA.Start();
return taskA;
}
public void InfoControl()
{
MessageBox.Show(textBox1.Text);
}
}