如何在Quartz.Net中将参数发送给类 [英] How to send argument to class in Quartz.Net

查看:166
本文介绍了如何在Quartz.Net中将参数发送给类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Quartz.Net(版本2)在每天的8:00和20:00(IntervalInHours = 12)中在类中运行方法

I'm using Quartz.Net (version 2) for running a method in a class every day at 8:00 and 20:00 (IntervalInHours = 12)

一切都很好,因为我使用了与Quartz.Net上的教程相同的作业和触发器,但是我需要在类中传递一些参数,并基于这些参数运行方法.

Everything is OK since I used the same job and triggers as the tutorials on Quartz.Net, but I need to pass some arguments in the class and run the method bases on those arguments.

有人可以帮我在使用Quartz.Net时如何使用参数吗?

Can any one help me how I can use arguments while using Quartz.Net?

推荐答案

您可以使用 JobDataMap

jobDetail.JobDataMap["jobSays"] = "Hello World!";
jobDetail.JobDataMap["myFloatValue"] =  3.141f;
jobDetail.JobDataMap["myStateData"] = new ArrayList(); 

public class DumbJob : IJob
{
    public void Execute(JobExecutionContext context)
    {
        string instName = context.JobDetail.Name;
        string instGroup = context.JobDetail.Group;

        JobDataMap dataMap = context.JobDetail.JobDataMap;

        string jobSays = dataMap.GetString("jobSays");
        float myFloatValue = dataMap.GetFloat("myFloatValue");
        ArrayList state = (ArrayList) dataMap["myStateData"];
        state.Add(DateTime.UtcNow);

        Console.WriteLine("Instance {0} of DumbJob says: {1}", instName, jobSays);
    }
} 

这篇关于如何在Quartz.Net中将参数发送给类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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