-2
  1. List item

I am trying to implement Quartz.Net in my project, I have placed two .cs where I declare public classes, however, the code that I incorporate, gives me errors, which I detail below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Quartz;
using Quartz.Listener;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;

namespace WEB_Project.Models
{
    public class EmailJob : IJob /*Error 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);
                }
            }
        }
    }
}
  • In this line, the error appears: enter image description here I already tried to place the IJob call in this way: Quartz.IJob, but it does not work either.

In the other .cs, I have the JOB, but it also gives me an error, I explain it below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Quartz;
using Quartz.Impl;
using System.Threading.Tasks;

namespace WEB_Project.Models
{
    public class JobScheduler
    {
        public void Start(DateTime date)
        {
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); /*Error Line*/
            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);
        }
    }
}
  • In this line, the error appears: enter image description here These are the mistakes that the implementation of Quartz gives me, any idea of how to fix it?
  • 2
    Possible duplicate of [Quartz: Does not implement interface member](https://stackoverflow.com/questions/41944213/quartz-does-not-implement-interface-member) – vadzim dvorak Aug 24 '18 at 14:53
  • Vadzim Dvorak. How I explained in the description, I already implemented that possible solution and I DO NOT WORK...!!! – Broodwing009 Aug 24 '18 at 14:57
  • also, I already reinstalled the Quartz library and I also installed the secondary library: Install-Package Quartz -Version 3.0.0-alpha1 -Pre. And it did not work either – Broodwing009 Aug 24 '18 at 15:09
  • Please _edit_ your question and include the actual text of the errors and **not** screen shots! – Chris Dunaway Aug 24 '18 at 16:04
  • The error seems fairly clear, though. It says that your `Execute` method does not have the proper return type of `Task`. – Chris Dunaway Aug 24 '18 at 16:07
  • Add 'using Quartz.Job' as the code is pulling the wrong IScheduler interface from Threading.Tasks – JAZ Aug 24 '18 at 16:09
  • Only served me 'using Quartz.Job', the other ( 'using Quartz.Job') does not serve me, It keeps showing me the same error – Broodwing009 Aug 24 '18 at 19:55

1 Answers1

-1

Finally I could solve the problem, thanks to those who helped me and others, thank you very much for nothing ... I leave the code, so that anyone who has the same mistakes I had, know how to fix it and do not confuse it with a link that be taken as a duplicate ...

First Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Quartz;
using Quartz.Listener;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;

namespace WEB_Project.Models
{
    public class EmailJob : IJob 
    {
        public Task 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);
                }
            }
          return Task.CompletedTask;
        }
    }
}

Second Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Quartz;
using Quartz.Impl;
using System.Net;
using System.Net.Mail;
using Quartz.Logging;
using System.Threading.Tasks;

namespace WEB_Project.Models
{
    public class JobScheduler
    {
        public static async void Start()
        {
            IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler();
            await scheduler.Start();

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

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

            ITrigger trigger1 = TriggerBuilder.Create()
                .WithIdentity("trigger_1", "group_1")
                .StartNow()
                .WithSimpleSchedule(x => x
                    .WithIntervalInSeconds(20)
                    .RepeatForever())
                .Build();

            await scheduler.ScheduleJob(job, trigger1);
        }
    }
}