-1

type of StdSchedulerFactory.GetDefaultScheduler() is task not IScheduler,so I got following error.

how can I fix this?

image

Nouman Ch
  • 4,023
  • 4
  • 29
  • 42
Leo
  • 1
  • 1

1 Answers1

0

You have to await for the result. I suppose you are not awaiting.

StdSchedulerFactory factory = new StdSchedulerFactory(props);
IScheduler scheduler = await factory.GetScheduler();
await scheduler.Start();

Here is complete example from Quartz docs.

private static async Task RunProgram()
    {
        try
        {
            // Grab the Scheduler instance from the Factory
            NameValueCollection props = new NameValueCollection
            {
                { "quartz.serializer.type", "binary" }
            };
            StdSchedulerFactory factory = new StdSchedulerFactory(props);
            IScheduler scheduler = await factory.GetScheduler();

            // and start it off
            await scheduler.Start();

            // some sleep to show what's happening
            await Task.Delay(TimeSpan.FromSeconds(60));

            // and last shut down the scheduler when you are ready to close your program
            await scheduler.Shutdown();
        }
        catch (SchedulerException se)
        {
            await Console.Error.WriteLineAsync(se.ToString());
        }
    }
Karel Kral
  • 5,297
  • 6
  • 40
  • 50
  • I use Quartz.net version:2.6,and then everything is OK,and now could you please tell me how to config my Quartz.net,such as restrict CrystalQuartz.Remote. thank you very much . – Leo Mar 11 '19 at 13:44
  • @Leo In your comment you are writing "net framework version:4.5.2, quartz.net version:3.0.4" and here 2.6. So what version of Quartz? – Karel Kral Mar 11 '19 at 14:10
  • sorry,I use quartz.net version:3.0.4 before,but it didnt work properly,so I change it to version:2.6,and errors were gone , I just dont know what goin on there.question mark. – Leo Mar 13 '19 at 09:29
  • @Leo As I can see, version 2.6 and 3.0.4 differs. Version 3.0.4 uses asynchronous methods. So you can use this version if you write code like this `IScheduler scheduler = await factory.GetScheduler();` See https://stackoverflow.com/questions/14455293/how-and-when-to-use-async-and-await. Please mark my answer as accepted. – Karel Kral Mar 13 '19 at 14:53