public class JobRunner
{
internal Timer Timer;
internal readonly IEnumerable<YuartzJob> Jobs;
public void Start()
{
this.Timer = new Timer(5000);
this.Timer.Elapsed += Timer_Elapsed;
this.Timer.Start();
}
public void Stop()
{
this.Timer.Stop();
}
internal void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
foreach (var job in Jobs)
{
MyActivator.RunJob(job);
}
}
}
public class MyActivator
{
public static void RunJob(YuartzJob job)
{
var objectHandle = Activator.CreateInstance(job.AssemblyName, job.ClassName).Unwrap();
var currentJob = (IJob)objectHandle;
currentJob.Run();
}
}
在我使用 MyActivator.RunJob(job) 的地方我应该怎么做:
- 我应该使用 ThreadPool 调用 MyActivator.RunJob 吗?
- 我应该使用 Threads 调用 MyActivator.RunJob 吗?
- 我应该使用 BackgroundWorker 调用 MyActivator.RunJob 吗?
- 它是否以这种方式工作而不做任何事情?