从 Quartz.NET 2 迁移到 3 铸造错误 [英] Migrating from Quartz.NET 2 to 3 Casting Error

查看:33
本文介绍了从 Quartz.NET 2 迁移到 3 铸造错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于从 Quartz.Net 2 升级到 3,其中现在包括 await/async 方法.我已按照迁移文档中的所有说明进行操作,但在以下初始化(标记行)时遇到问题:

My question is regarding the upgrade from Quartz.Net 2 to 3 in which now includes await/async methods. I have followed all the instructions in the migration document but I'm having an issue at the following initializaiton (marked line):

 public partial class BMOSSService : ServiceBase
{
    private EventLogger _eventLogger = new EventLogger("BMOSS");
    private static ISchedulerFactory _scheduleFactory = new StdSchedulerFactory();
    ****private static IScheduler _scheduler = _scheduleFactory.GetScheduler();****

    private static readonly ILog _log = LogManager.GetLogger("BlackBox.BMOSS.Scheduler");
    private static readonly ILog _logToDo = LogManager.GetLogger("BlackBox.BMOSS.Scheduler.ToDo");

    private static bool _forceStop = false;

    public BMOSSService() ...

我知道调度器工厂现在需要 await 指令,但问题是这是一个全局声明,我可以将 asynch 关键字添加到类中,我该如何解决这个问题?有什么想法吗?

I understand that the scheduler factory now needs the await instruction but the issue is that this is a global declaration and I can add the asynch keyword to the class how can I fix this? any ideas?

谢谢

推荐答案

最后我解决了这个问题.我就是这样做的.首先,我必须从以下位置更改变量初始化:

Finally I resolved the issue. This is how I did it. First I had to change the variable initialization from:

private static IScheduler _scheduler = _scheduleFactory.GetScheduler();

private static Task<IScheduler> _scheduler = _scheduleFactory.GetScheduler();

这让我改变了一些其他的方法实现来返回一个任务和一些等待,现在一切都在运行.诀窍是接收这样的值:

This made me change some other method implementations to return a Task and some await and everything is running now. The trick was to receive the value like this:

 public async Task RegisterJobsProcessAsync(Task<IScheduler> scheduler)
        {
            _log.Info("Job registering process begins");

            this._scheduler = scheduler.Result;

            await UnRegisterJobsAsync();
            await RegisterJobsAsync();

            _log.Info("Job registering process ends");
        }

这篇关于从 Quartz.NET 2 迁移到 3 铸造错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆