Gullu Gullu - 1 month ago 11
C# Question

what is the correct way to clear quartz.net ramjobstore without re-starting app in c#

If there is a way to do this , can I also confirm by viewing the ramstore before and after clear. How can we view the contents of the ramstore programmatically ? In my case I am reading all job and trigger info from file. On some custom event I need to stop the scheduler and start all over again without re-starting the app.
thank you

Answer

The RamJobStore from the Quartz.NET frameworks provides several methods to view it's contents, the easiest is the 'GetJobGroupNames()' and 'GetJobNames()' functions:

public virtual string[] GetJobGroupNames( 
  SchedulingContext ctxt
)

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

You can use it like this:

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

Of course this is not what you want, since it will just show a message box for all the jobs you have in your RamJobStore, but it does allow you to view the contents of the entire store. Furthermore you can now use two methods to remove all the jobs. You can either use the function 'RemoveJob()' or 'Shutdown()'.

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

This will just remove all the jobs on the object, but might be time consuming on large store(s). Therefore there is also a 'Shutdown()' function, which just removes the entire store from memory (after which you can create a new one).

I put ... in some of the function(s), which is your SchedulingContext you've used to store the jobs in the first place.

Comments