How do I run jobs in a specific millisecond? #976
Unanswered
mojtabamn22
asked this question in
General
Replies: 2 comments 7 replies
-
If you are building a real time system I'm afraid that a scheduling library will have hard time to meet your expectations. There's always some overhead which will cause jobs to run some milliseconds late. Can you elaborate how the code did not run at specified time? Was it off by couple milliseconds or didn't it run at all? |
Beta Was this translation helpful? Give feedback.
4 replies
-
@lahma public class HelloJob : IJob
{
Form1 frm = new Form1();
public async Task Execute(IJobExecutionContext context)
{
//await Console.Out.WriteLineAsync("Greetings from HelloJob!" + DateTime.Now.ToString("hh:mm:ss.fff"));
await Task.Run(() =>
{
frm.dataGridView1.Rows.Add(DateTime.Now.ToString("hh:mm:ss.fff"));
});
}
}
private async void button1_Click(object sender, EventArgs e)
{
StdSchedulerFactory factory = new StdSchedulerFactory();
IScheduler scheduler = await factory.GetScheduler();
// and start it off
await scheduler.Start();
// define the job and tie it to our HelloJob class
IJobDetail job = JobBuilder.Create<HelloJob>()
.WithIdentity("job1", "group1")
.Build();
// Trigger the job to run now, and then repeat every 10 seconds
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartAt(DateTime.Today.Add(new TimeSpan(0, 18, 39, 20, 900)))
.WithSimpleSchedule(x => x
.WithInterval(TimeSpan.FromMilliseconds(50))
.WithRepeatCount(30))
.Build();
// Tell quartz to schedule the job using our trigger
await scheduler.ScheduleJob(job, trigger);
// some sleep to show what's happening
await Task.Delay(TimeSpan.FromSeconds(30));
// and last shut down the scheduler when you are ready to close your program
await scheduler.Shutdown();
Form1 frm = new Form1();
frm.textBox1.Text = "Finish";
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want jobs to start running in certain milliseconds.
For example, start at 2:00:00.200, 2:00:00.400, 2:00:00.600, and so on. It may take a few minutes to complete these tasks, it is important to me that they are performed at the specified time (milliseconds).
I used the following code to do this but it did not run at the specified time
Beta Was this translation helpful? Give feedback.
All reactions