计划任务-在不重新启动c#中的应用程序的情况下,清除quartz.net ramjobstore的正确方法是什么



如果有办法做到这一点,我还可以通过查看清除前后的ramstore来确认吗。我们如何以编程方式查看ramstore的内容?在我的情况下,我正在从文件中读取所有作业和触发器信息。在一些自定义事件中,我需要停止调度程序并重新启动,而无需重新启动应用程序。感谢

Quartz.NET框架中的RamJobStore提供了几种查看其内容的方法,最简单的是"GetJobGroupNames()"one_answers"GetJobNames(()"函数:

public virtual string[] GetJobGroupNames( 
  SchedulingContext ctxt
)
public virtual string[] GetJobNames( 
  SchedulingContext ctxt,
  string groupName
)

你可以这样使用它:

foreach(string group in ramstore.GetJobGroupNames(...))
  foreach(string job in ramstore.GetJobNames(..., group))
    MessageBox.Show(String.Format("{0} (Group: {1})", job, group));

当然,这不是您想要的,因为它只会显示RamJobStore中所有作业的消息框,但它确实允许您查看整个商店的内容。此外,您现在可以使用两种方法删除所有作业。您可以使用函数RemoveJob()或Shutdown()。

foreach(string group in ramstore.GetJobGroupNames(...))
  foreach(string job in ramstore.GetJobNames(..., group))
    ramstore.RemoveJob(..., job, group);

这只会删除对象上的所有作业,但在大型存储上可能会很耗时。因此,还有一个"Shutdown()"函数,它只是从内存中删除整个存储(之后可以创建一个新存储)。

我把。。。在一些函数中,也就是您最初用于存储作业的SchedulingContext

fyi来自文档:

Never use a JobStore instance directly in your code. 
For some reason many people attempt to do this.
The JobStore is for behind-the-scenes use of Quartz itself. 
You have to tell Quartz (through configuration) which JobStore 
to use, but then you should only work with the Scheduler interface
in your code.

在此处找到:http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/job-stores.html

根据我对石英的有限经验,我认为你可以获取调度器的内容,然后关闭调度器并启动一个新的调度器?

最新更新