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

发布于 2024-09-28 14:03:44 字数 197 浏览 3 评论 0原文

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

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

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

I need to be able to get the properties (i.e. cron expression or type of simple trigger (daily, hourly, etc) and it's parameters) of a trigger in C#, and display them and also let them be modified. I have this right now:

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

But I can't find any methods to let me access this information. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水波映月 2024-10-05 14:03:44

如果

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...
}

How about

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
}

If efficiency is important, you can also do this in one loop:

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...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文