gpt4 book ai didi

triggers - 每次使用Quartz.NET都会出现错误

转载 作者:行者123 更新时间:2023-12-01 18:06:08 27 4
gpt4 key购买 nike

我在这一行收到一个错误:

Cannot implicitly convert type 'System.Threading.Tasks.Task' to 'Quartz.IScheduler'. An explicit conversion exists (are you missing a cast?)

如何解决;我不明白?请帮忙!

IScheduler 调度程序 = StdSchedulerFactory.GetDefaultScheduler();

   public static void Start()
{
try
{
//Construct scheduler factory
//IScheduler scheduler = schedulerFactory.GetScheduler();

// IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();

IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();

IJobDetail job = JobBuilder.Create<HelloJob>()
.WithIdentity("jobName", "jobGroup")
.Build();

ITrigger trigger = TriggerBuilder.Create()
.WithSimpleSchedule(s => s.WithIntervalInSeconds(60).RepeatForever())
.StartNow()
.Build();

scheduler.ScheduleJob(job, trigger);

// scheduler.Start();

}

catch (SchedulerException se)
{
//Console.WriteLine(se);
}
}
}

public class HelloJob : IJob
{
private TBPESContext db = new TBPESContext();
public void Execute(IJobExecutionContext context)
{
var AuthorName = from twitterAccount in db.Twitter_Account
from c in twitterAccount.Courses
select twitterAccount.Author_Name;

foreach (var item in AuthorName)
{
TweetCrawler.SaveTweets(item);
}


throw new NotImplementedException();
}
}

最佳答案

从 Quartz 3.0.0 版本开始:https://www.quartz-scheduler.net/2017/12/30/quartznet-3.0-released.html :

  • SimpleThreadPool 消失了,旧拥有的线程消失了

  • IJob 接口(interface)现在返回一个任务

所以我在这里放了要使用的示例:

class Program
{
static void Main(string[] args)
{
JobScheduler jobScheduler = new JobScheduler();
jobScheduler.Start();
Console.ReadLine();
}
}
public class JobScheduler
{
public async void Start()
{
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
IScheduler scheduler = await schedulerFactory.GetScheduler();
await scheduler.Start();

IJobDetail job = JobBuilder.Create<HelloJob>().Build();

ITrigger trigger = TriggerBuilder.Create()

.WithIdentity("HelloJob ", "GreetingGroup")

.WithCronSchedule("0 0/1 * 1/1 * ? *")

.StartAt(DateTime.UtcNow)

.WithPriority(1)

.Build();

await scheduler.ScheduleJob(job, trigger);

}

}
public class HelloJob : IJob
{
Task IJob.Execute(IJobExecutionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
Task taskA = new Task(() => Console.WriteLine("Hello from task at {0}", DateTime.Now.ToString()));
taskA.Start();
return taskA;
}
}

关于triggers - 每次使用Quartz.NET都会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40437430/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com