Exemplo n.º 1
0
        static async Task Main(string[] args)
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            CreateServiceProvider();

            // get instance of logger
            var logger = serviceProvider.GetService <ILogger <Program> >();

            var config = new dotnetCoreWindowsServiceCore.Config()
            {
                Timeout = 3
            };
            var _coreClass = new dotnetCoreWindowsServiceCore.CoreClass(logger, config);
            await _coreClass.RunAsync(cts.Token);
        }
Exemplo n.º 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("started");

            stoppingToken.Register(CancelledRequested);

            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    var _coreClass = new dotnetCoreWindowsServiceCore.CoreClass(_logger, _config);
                    _logger.LogInformation("instance created");
                    await _coreClass.RunAsync(stoppingToken);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error, ErrorGuid: [3610bb5c-75c4-40a5-810c-2c748c365218]");
                    await Task.Delay(3000, stoppingToken);
                }
            }
        }