我是Quartz.net的新用户,正在尝试一个快速入门示例,其中介绍了一些如何不触发任何内容运行的示例。
private static async Task RunProgramRunExample()
{
try
{
// Grab the Scheduler instance from the Factory
NameValueCollection props = new NameValueCollection
{
{ "quartz.serializer.type", "binary" }
};
StdSchedulerFactory factory = new StdSchedulerFactory(props);
IScheduler scheduler = await factory.GetScheduler();
// and start it off
await scheduler.Start();
IJobDetail job = JobBuilder.Create<ClothingJob>()
.WithIdentity("clothing", "group1")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(3)
.RepeatForever())
.Build();
// Tell quartz to schedule the job using our trigger
await scheduler.ScheduleJob(job, trigger);
}
catch (SchedulerException se)
{
Console.WriteLine(se);
}
}
public partial class ClothingJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
try
{
await Console.Out.WriteLineAsync("HelloJob is executing.");
}
catch (JobExecutionException ex)
{
}
}
}
//控制台主控
static void Main(string[] args)
{
RunProgramRunExample().GetAwaiter().GetResult();
}
答案 0 :(得分:0)
您的代码很好,但是在作业运行之前已经完成。
将主线更改为:
static void Main(string[] args)
{
RunProgramRunExample().GetAwaiter().GetResult();
var name = Console.ReadLine();
}