You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to retrieve the IJob object for the scheduled job based of the specific name?
I was hoping I would be able to do this by calling a method such as JobManager.GetSchedule("name").ScheduledJobs(). This would return a List of IJobs which are yet to be executed.
Is there a way to do this? Or would I have to look into other ways such as storing jobs in a database.
Thanks
The text was updated successfully, but these errors were encountered:
I don't think you can get the IJob objects as they are internally stored as List<Action>. If you just want to execute the Jobs though then you can do it with a bit of reflection:
internal class Program
{
private static void Main(string[] args)
{
var registry = new Registry();
registry.Schedule<CountingJob>().WithName("Job1").ToRunEvery(10).Seconds();
JobManager.Initialize(registry);
var schedule = JobManager.GetSchedule("Job1");
var scheduleType = schedule.GetType();
var jobs = scheduleType
.GetProperty("Jobs", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(schedule) as List<Action>;
var job = jobs.FirstOrDefault();
for (int i = 0; i < 5; i++)
{
job.Invoke();
}
Console.ReadLine();
}
internal class CountingJob : IJob
{
private static int counter;
public void Execute()
{
Console.WriteLine(++counter);
}
}
}
Is there a way to retrieve the
IJob
object for the scheduled job based of the specific name?I was hoping I would be able to do this by calling a method such as
JobManager.GetSchedule("name").ScheduledJobs()
. This would return aList
ofIJob
s which are yet to be executed.Is there a way to do this? Or would I have to look into other ways such as storing jobs in a database.
Thanks
The text was updated successfully, but these errors were encountered: