Search code examples
c#quartz.netquartzijobfactory

Error #CS0738 'Notification' does not implement interface member 'IJob.Execute(IJobExecutionContext)'. 'Notification.Execute(IJobExecutionContext)'


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);
        }
    }
}

For this line of code I am getting such a warning.

ERROR :

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

EDIT 1 : add my scheduling code

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

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

I am getting this error here too

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

Please help me ...


Solution

  • It might be beneficial to look at https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/index.html as it looks like some of your code is written for Version 2.2 but the error messages would suggest you are using Version 3.

    In particular your second error may be because you are missing awaits, ie

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

    should be

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

    Also your first signature should be

      public async Task Execute(IJobExecutionContext context)
    

    and presumably you need to use await in the actual code.