Exemple #1
0
        protected override void OnStart(string[] args)
        {
            cancelSource = new CancellationTokenSource();
            StartProcess objProcess = new StartProcess();

            if (!int.TryParse(ConfigurationManager.AppSettings["TimerInterval"], out TimerInterval))
            {
                TimerInterval = 60000;
            }

            Task.Run(async() =>
            {
                try
                {
                    while (!cancelSource.IsCancellationRequested)
                    {
                        await objProcess.StartPolling(cancelSource);
                        await Task.Delay(TimerInterval, cancelSource.Token);
                    }
                }
                catch (OperationCanceledException)
                {
                    Console.WriteLine("Canceled!");
                }
            });

            //Task.Run(async () =>
            //{
            //    try
            //    {
            //        await objProcess.StartConsuming(cancelSource);
            //    }
            //    catch (OperationCanceledException)
            //    {
            //        Console.WriteLine("Canceled!");
            //    }
            //});
        }