首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >错误#CS0738‘通知’没有实现接口成员'IJob.Execute(IJobExecutionContext)‘。'Notification.Execute(IJobExecutionContext)‘

错误#CS0738‘通知’没有实现接口成员'IJob.Execute(IJobExecutionContext)‘。'Notification.Execute(IJobExecutionContext)‘
EN

Stack Overflow用户
提问于 2018-06-03 00:28:19
回答 2查看 1.2K关注 0票数 0
using System;
using Quartz;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hatirlaticiapp
{
    public class Notification : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap data = context.JobDetail.JobDataMap;
            Task task = (Task)data["Task"];
            task.OnNotificationStarted(task, EventArgs.Empty);
        }
    }
}

对于这行代码,我得到了这样的警告。

错误:

错误通知‘CS0738’不实现接口成员'IJob.Execute(IJobExecutionContext)‘。“Notification.Execute(IJobExecutionContext)”“无法实现”“IJob.Execute(IJobExecutionContext)”“,因为它没有匹配的返回类型”“Task”“。”

编辑1:添加我的调度代码

public class NotificationController : IController<Task>
{
    ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
    IScheduler scheduler;

    public NotificationController()
    {            
        scheduler = schedulerFactory.GetScheduler();
        scheduler.Start();
    }
}

我在这里也得到了这个错误

错误:无法将类型'System.Threading.Tasks.Task‘隐式转换为“Quartz.IScheduler”。存在显式转换(是否缺少强制转换?)

请帮帮我。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-05 00:36:43

查看https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/index.html可能会有所帮助,因为它看起来您的一些代码是为版本2.2编写的,但错误消息会提示您正在使用版本3。

特别是你的第二个错误可能是因为你错过了等待,即

  scheduler = schedulerFactory.GetScheduler();
  scheduler.Start();

应该是

  scheduler = await schedulerFactory.GetScheduler();
  await scheduler.Start();

另外,你的第一个签名应该是

  public async Task Execute(IJobExecutionContext context)

并且假设您需要在实际代码中使用await

票数 2
EN

Stack Overflow用户

发布于 2018-06-03 01:21:14

阅读整个异常,末尾写着

... because it does not have the matching return type of 'Task'.

将返回值从void改为Task

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50658932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档