Example #1
0
        public override async Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogDebug("Application startup");
            _logger.LogDebug($"Integration with user activity: {_applicationConfiguration.UserActivityIntegration}");
            _logger.LogDebug($"Count system time: {_applicationConfiguration.CountSystemRunningTime}");
            _logger.LogDebug($"Shutting down computer after time exceeded: {_applicationConfiguration.TurnOffComputerAfterTimeExceeded}");

            try
            {
                _applicationService.ApplicationStartup();

                if (_applicationConfiguration.UserActivityIntegration)
                {
                    _applicationService.UserActivityDetected += OnUserActivityDetected;

                    StartTimers();

                    await _applicationService.HookUserActivity();
                }
            }

            catch (Exception e)
            {
                _logger.LogError(e, "Exception occured during startup");

                _applicationService.ApplicationShutdown();
            }

            finally
            {
                _hostApplicationLifetime.StopApplication();
            }
        }