Exemplo n.º 1
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var myJobListener       = new MyJobListener();
            var myTriggerListener   = new MyTriggerListener();
            var mySchedulerListener = new MySchedulerListener();

            NameValueCollection props = new NameValueCollection()
            {
                { "quartz.serializer.type", "binary" }
            };

            StdSchedulerFactory factory = new StdSchedulerFactory(props);

            // await InstanceForOneJob(myJobListener, factory);
            // await InstanceForJobsInGroup(myJobListener, factory);
            // await InstanceForJobsInDifferentGroups(myJobListener, factory);
            await InstanceForOneTrigger(myTriggerListener, factory);

            //Adding a SchedulerListener:
            //scheduler.ListenerManager.AddSchedulerListener(mySchedulerListener);

            //Removing a SchedulerListener:
            //scheduler.ListenerManager.RemoveSchedulerListener(mySchedListener);

            Console.ReadLine();
        }
Exemplo n.º 2
0
        private static async Task InstanceForOneTrigger(MyTriggerListener myTriggerListener, StdSchedulerFactory factory)
        {
            var mySchedulerListener = new MySchedulerListener();

            IScheduler sched = await factory.GetScheduler();

            await sched.Start();

            IJobDetail job = JobBuilder.Create <DumbJob>().WithIdentity("myJob")
                             .UsingJobData("jobSays", "Hello World!")
                             .UsingJobData("myFloatValue", 3.141f)
                             .Build();

            ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create().WithIdentity("trigger")
                                     .StartNow()
                                     .WithSimpleSchedule(x => x.WithIntervalInSeconds(4)
                                                         .WithRepeatCount(4))
                                     .Build();

            //Adding a TriggerListener that is interested in a particular trigger:
            sched.ListenerManager.AddTriggerListener(myTriggerListener, KeyMatcher <TriggerKey> .KeyEquals(new TriggerKey("trigger")));
            sched.ListenerManager.AddSchedulerListener(mySchedulerListener);
            await sched.ScheduleJob(job, trigger);
        }