Quartz:不实现接口成员 [英] Quartz: Does not implement interface member
问题描述
我正在使用 Quartz 并使用示例代码并得到错误:
I am using Quartz and using sample code and get the error:
CS0738 'EmailJob' 没有实现接口成员IJob.Execute(IJobExecutionContext)
.EmailJob.Execute(IJobExecutionContext)
无法实现 IJob.Execute(IJobExecutionContext)
,因为它没有 >Task
的匹配返回类型.>
CS0738 'EmailJob' does not implement interface member
IJob.Execute(IJobExecutionContext)
.EmailJob.Execute(IJobExecutionContext)
cannot implementIJob.Execute(IJobExecutionContext)
because it does not > have the matching return type ofTask
.
这是我第一次使用 Quartz,因此不胜感激.
This is my first go at Quartz so any help would be kindly appreciated.
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
I got the code directly from this wonderful article: http://www.mikesdotnetting.com/article/254/scheduled-tasks-in-asp-net-with-quartz-net
推荐答案
我刚刚测试了你的代码,它在我这边编译时没有任何变化.您的问题可能是错误的命名空间导入.您可以尝试使用完整的命名空间,如下所示:
I just tested your code and it compiles without any changes on my side. Your problem is maybe a wrong namespace import. You can try with the full namespace like this:
public class EmailJob : Quartz.IJob
{
public void Execute(Quartz.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);
}
}
}
// ...
}
这篇关于Quartz:不实现接口成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!