在Quartz.NET中获取触发器属性

时间:2010-10-22 08:59:45

标签: c# quartz.net

我需要能够在C#中获取触发器的属性(即cron表达式或简单触发器类型(每日,每小时等)及其参数),并显示它们并让它们进行修改。我现在有这个:

Trigger[] trigger = sched.GetTriggersOfJob(id, groupid);

但我找不到任何让我访问此信息的方法。有什么想法吗?

1 个答案:

答案 0 :(得分:5)

怎么样

Trigger[] triggers = sched.GetTriggersOfJob(id, groupid);
foreach (SimpleTrigger simpleTrigger in triggers.OfType<SimpleTrigger>())
{
   //extract simple trigger info
}

foreach (CronTrigger cronTrigger in triggers.OfType<CronTrigger>())
{
  //extract cron trigger info
}

如果效率很重要,您也可以在一个循环中执行此操作:

Trigger[] triggers = sched.GetTriggersOfJob(id, groupid);
foreach (var trigger in triggers)
{
   SimpleTrigger simpleTrigger = trigger as SimpleTrigger;
   if (simpleTrigger != null)
   {
     //handle simple trigger
     continue;
   }
   //same for CronTrigger...
}