views:

31

answers:

1

Hi all, this may be a general question on sharing 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");
            }
                  }
A: 

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");
Ronald Wildenberg
Cheers buddy, it's telling me 'Scheduler with name 'DefaultQuartzScheduler' already exists though :(
Chris
That's weird, I use the exact same two lines of code in a project and this works. But I added another way to get the same result.
Ronald Wildenberg
Now I'm getting object reference errors whatever I do...hmm. I've editted my question with the code I'm using, maybe I'm doing something wrong. I'm trying to make an ASP.NET page where they can edit the job details in the datamap.
Chris
Can you take a look at what `SchedulerRepository.Instance.LookupAll()` returns? You should get a list of all registered schedulers. From this list (which probably contains just one scheduler) you should be able to get the scheduler you want.
Ronald Wildenberg