Exemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await commandService.AddModulesAsync(assembly : Assembly.GetEntryAssembly(),
                                                 services : serviceProvider);

            await clientWrapper.StartAsync();

            client.MessageReceived += MessageReceived;

            await Task.Delay(-1);
        }
Exemplo n.º 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await clientWrapper.StartAsync();

            do
            {
                var now     = DateTime.Now;
                var nextrun = schedule.GetNextOccurrence(now);
                if (now > nextRun)
                {
                    try
                    {
                        await Process();
                    }
                    catch (Exception ex)
                    {
                        logger.LogCritical(ex, "An unexpected error occured in the background service.");
                    }
                    nextRun = schedule.GetNextOccurrence(DateTime.Now);
                }
                await Task.Delay(5000, stoppingToken); //5 seconds delay
            }while (!stoppingToken.IsCancellationRequested);
        }