gpt4 book ai didi

c# - quartz : Does not implement interface member

转载 作者:行者123 更新时间:2023-11-30 14:24:12 27 4
gpt4 key购买 nike

我正在使用 Quartz 并使用示例代码并得到错误:

CS0738 'EmailJob' does not implement interface member IJob.Execute(IJobExecutionContext). EmailJob.Execute(IJobExecutionContext) cannot implement IJob.Execute(IJobExecutionContext) because it does not > have the matching return type of Task.

这是我第一次使用 Quartz,如有任何帮助,我们将不胜感激。

public class EmailJob : IJob  // <<<--- Error on this line
{
public void Execute(IJobExecutionContext context)
{
using (var message = new MailMessage("user@gmail.com", "user@live.co.uk"))
{
message.Subject = "Test";
message.Body = "Test at " + DateTime.Now;
using (SmtpClient client = new SmtpClient
{
EnableSsl = true,
Host = "smtp.gmail.com",
Port = 587,
Credentials = new NetworkCredential("user@gmail.com", "password")
})
{
client.Send(message);
}
}
}

public class JobScheduler
{
public static void Start()
{
IScheduler scheduler = (IScheduler)StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();

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

ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
)
.Build();

scheduler.ScheduleJob(job, trigger);
}
}

我直接从这篇精彩的文章中获得了代码:http://www.mikesdotnetting.com/article/254/scheduled-tasks-in-asp-net-with-quartz-net

最佳答案

在我看来您使用的是 3.0 版本(仔细检查您从 Nuget 获取的包)。 IJob 界面已更改。 Execute 方法现在返回一个 Task 而不是一个 void 方法(这解释了为什么你会看到你所看到的问题)。

任务执行(
IJobExecutionContext 上下文
)

Here are the 3.0 docs .

正如 Bidou 所指出的,第 3 版仍处于 alpha 阶段。您需要卸载此版本并将其替换为以前的版本,或者相应地调整您的代码。

关于c# - quartz : Does not implement interface member,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41944213/

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