Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class JobBase : IJob,IInterruptableJob
- {
- private Thread currentThread;
- private ILog logger;
- public JobBase(ILog logger)
- {
- this.logger=logger;
- }
- public void Execute(IJobExecutionContext context)
- {
- var thread = new Thread(()=>
- {
- try
- {
- this.ExecuteJob(context);
- }
- catch(Exception ex)
- {
- this.logger.ErrorFormat("Unhandled exception {0}",ex.ToString());
- }
- });
- thread.Start();
- this.currentThread = thread;
- this.currentThread.Join();
- }
- public abstract void ExecuteJob(IJobExecutionContext context);
- public void Interrupt()
- {
- currentThread.Abort();
- }
- }
- public class TestJob :JobBase
- {
- private ILog logger;
- public TeJob(ILog logger):base(logger)
- {
- }
- public override ExecuteJob(IJobExecutionContext context)
- {
- }
- }
- SchedulerFactory factory = new StdSchedulerFactor();
- Scheduler scheduler = factory.getScheduler();
- scheduler.start();
- scheduler.shutdown();
- if(flag==true)
- {
- scheduler.start();
- scheduler.scheduleJob(jobDetail, simpleTrigger);
- }
- else if(flag==false)
- {
- scheduler.shutdown();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement