Getting scheduler from another method (Quartz.NET). Or general method question
this may be a general question on shar开发者_如何转开发ing variables but here goes.
I'm using a GridView on a webpage to edit each job, and I need to hook up to each 'rowbound' event to get some data from the jobDataMap.
Anyway, the scheduler starts in the Page_Load method (creating the variable sched I can use to access the info), but from any other event/method I can't access the sched variable. How do I allow myself to do this?
Thanks
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Header)
{
var schedulerFactory = new StdSchedulerFactory();
IScheduler sched = schedulerFactory.GetScheduler();
string schedID = sched.SchedulerInstanceId;
string id = e.Row.Cells[0].Text;
string groupid = e.Row.Cells[1].Text;
JobDetail jobDetail = sched.GetJobDetail(id, groupid);
Trigger[] trigger = sched.GetTriggersOfJob(id, groupid);
JobDataMap dataMap = jobDetail.JobDataMap;
e.Row.Cells[3].Text = dataMap.GetString("nameid");
}
}
You can use the following code for this:
var schedulerFactory = new StdSchedulerFactory();
IScheduler scheduler = schedulerFactory.GetScheduler();
If your scheduler has a specific name, there is an overload of GetScheduler
that accepts a string name.
Or you could use the following:
IScheduler scheduler =
SchedulerRepository.Instance.Lookup("DefaultQuartzScheduler");
@see
source StdSchedulerFactory.cs
line 373 string schedName = cfg.GetStringProperty(PropertySchedulerInstanceName, "QuartzScheduler");
so IScheduler scheduler =
SchedulerRepository.Instance.Lookup("QuartzScheduler"); is default
精彩评论