Esempio n. 1
0
        private Task RunMain(TimeSpan PullCommentsFrequency)
        {
            Scheduler.AddTask(ScheduledTask.NewImmediateTask(
                                  //Comes from Settings.PullCommentsFrequency, so will always be positive and no greater than 2^31-1 milliseconds
                                  PullCommentsFrequency,
                                  () => ActivityProcessComments.Execute()
                                  //async() => {await Tests();Scheduler.Stop();}
                                  ));

            /*
             * onShutdownSignal will synchronize a call to TaskScheduler.Stop using the current synchronization context,
             * which will only have an effect if the TaskScheduler is running;
             * the call is simply ignored if it is not running.
             * In order to ensure that the TaskScheduler is running when the call is synchronized,
             * only react to the CancelKeyPress event right before the TaskScheduler starts running;
             * if a CancelKeyPress event gets fired at this point,
             * then by the time it is synchronized to the current synchronization context the TaskScheduler will always be running.
             * Any CancelKeyPress events that are fired before this point will have the default behavior
             * of (presumably) immediately terminating all execution, which is acceptable before this point.
             */
            Console.CancelKeyPress += onShutdownSignal;
            Log.Bootstrap_.LogInfo("Setup complete, running application");
            //Execution will be within this method while the application is running
            return(Scheduler.Run());
        }