Exemplo n.º 1
0
        public HelloSwitcherService()
        {
            InitializeComponent();

            TaskScheduler.UnobservedTaskException      += (_, e) => Logger.RecordError(e.Exception);
            AppDomain.CurrentDomain.UnhandledException += (_, e) => Logger.RecordError(e.ExceptionObject);

            Settings = new Settings();
            Logger   = new Logger("operation.service.log", "error.service.log");

            _check = new Sample(
                TimeSpan.FromSeconds(1),
                (actionName, cancellationToken) => _switcher?.CheckAsync(actionName, cancellationToken));
        }
Exemplo n.º 2
0
        protected override async void OnStart(string[] args)
        {
            Logger.RecordOperation("Start");

            await Settings.LoadAsync();

            Logger.RecordOperation($"Settings IsLoaded: {Settings.IsLoaded}");

            _checkTokenSource?.Dispose();
            _checkTokenSource = new();

            _switcher = new DeviceSwitcher(Settings, Logger);
            await _switcher.CheckAsync("Initial Check", _checkTokenSource.Token);

            DeviceUsbHelper.UnregisterNotification(_notificationHandle);
            _notificationHandle = DeviceUsbHelper.RegisterServiceNotification(this.ServiceHandle);
        }