SHARE
TWEET

Untitled

a guest Jun 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class LoaderJob:IJob
  2. {
  3.     private PsgrContext _context;
  4.     public Task Execute(IJobExecutionContext context)
  5.     {
  6.  
  7.         return Task.Run(() =>
  8.         {
  9.             var q = _context.Photos(); //Тут уже работать с контекстом
  10.             Console.WriteLine("Execute");
  11.         });
  12.     }
  13.  
  14.     public LoaderJob()
  15.     {
  16.         _context = new PsgrContext();
  17.         Console.WriteLine("Ctor Test");
  18.     }
  19. }
  20.      
  21. NameValueCollection props = new NameValueCollection
  22.             {
  23.                 {"quartz.serializer.type", "binary"}
  24.             };
  25. StdSchedulerFactory factory = new StdSchedulerFactory(props);
  26. IScheduler scheduler = await factory.GetScheduler();
  27.  
  28. // and start it off
  29. await scheduler.Start();
  30.  
  31. // define the job and tie it to our HelloJob class
  32. IJobDetail job1 = JobBuilder.Create<LoaderJob>()
  33.     .WithIdentity("job1", "group1")
  34.     .Build();
  35.  
  36. // Trigger the job to run now, and then repeat every 10 seconds
  37. ITrigger trigger1 = TriggerBuilder.Create()
  38.     .WithIdentity("trigger1", "group1")
  39.     .StartNow()
  40.     .WithSimpleSchedule(x => x
  41.         .WithIntervalInSeconds(1)
  42.         .RepeatForever())
  43.     .Build();
  44.  
  45. // Tell quartz to schedule the job using our trigger
  46. var jobs = new Dictionary<IJobDetail, IReadOnlyCollection<ITrigger>>();
  47. jobs[job1] = new [] {trigger1};
  48.  
  49. await scheduler.ScheduleJobs(jobs, true);
  50.      
  51. Ctor Test
  52. Execute
  53. Ctor Test
  54. Execute
  55. Ctor Test
  56. Execute
  57. Ctor Test
  58. Execute
  59. Ctor Test
  60. Execute
  61. Ctor Test
  62. Execute
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top