首页 > 解决方案 > Quartz.net:GetDefaultScheduler() 的类型

问题描述

StdSchedulerFactory.GetDefaultScheduler() 的类型是任务不是 IScheduler,所以我收到以下错误。

我怎样才能解决这个问题?

图片

标签: quartz.net-3.0

解决方案


你必须await为结果。我想你没有在等待。

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

是来自 Quartz 文档的完整示例。

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

推荐阅读