/// <inheritdoc />
        protected override void Dispose(bool disposing)
        {
            _messagingCenter.Unsubscribe <object>(this, ToBackgroundMessages.StartBackgroundService);
            _messagingCenter.Unsubscribe <object>(this, ToBackgroundMessages.StopBackgroundService);
            _messagingCenter.Unsubscribe <object>(this, ToBackgroundMessages.GetBackgroundServiceState);

            base.Dispose(disposing);
        }
        private async void Cleanup()
        {
            StopPeriodicTasks();

            using (var mre = new ManualResetEventSlim())
            {
                await Task.Run(async() =>
                {
                    _cancellationTokenSource.Cancel();
                    await _backgroundService.StopAsync();
                    mre.Set();
                });

                if (!mre.Wait(_cleanupTimeout))
                {
                    Log.Error(_builder.ServiceName, "Background service did not cleanup within timeout time");
                }
            }

            ReleaseWakeLock();
            StopForeground(true);
            StopSelf();
            IsStarted = false;
            _messagingCenter.Send <object, BackgroundServiceState>(this,
                                                                   FromBackgroundMessages.BackgroundServiceState, new BackgroundServiceState(false));
            _messagingCenter.Unsubscribe <object, UpdateNotificationMessage>(this, ToBackgroundMessages.UpdateBackgroundServiceNotificationMessage);
        }
Beispiel #3
0
 private Task Cleanup()
 {
     return(_backgroundService?.StopAsync()
            .ContinueWith(task =>
     {
         if (_hasPeriodicTask)
         {
             StopHandlerThread();
         }
         ReleaseWakeLock();
         StopForeground(true);
         StopSelf();
         IsStarted = false;
         _messagingCenter.Send <object, BackgroundServiceState>(this,
                                                                FromBackgroundMessages.BackgroundServiceState, new BackgroundServiceState(false));
         _messagingCenter.Unsubscribe <object, UpdateNotificationMessage>(this, ToBackgroundMessages.UpdateBackgroundServiceNotificationMessage);
     }));
 }
        public void Init()
        {
            //_aimTimerNotificationService.Stop();
            AimTimerListItemViewModels.CollectionChanged -= AimTimerItemViewModels_CollectionChanged;
            //_aimTimerNotificationService.OnStatusChanged -= AimTimerNotificationService_OnStatusChanged;
            _messagingCenter.Unsubscribe <IAimTimerItem>(this, MessagingCenterMessages.AimTimerUpdated);

            AimTimerListItemViewModels.Clear();
            foreach (var aimTimerItem in _aimTimerService.GetActiveAimTimers())
            {
                AimTimerListItemViewModels.Add(_aimTimerItemViewModelFactory.Create(aimTimerItem));
            }

            //_aimTimerNotificationService.SetItemsToFollow(AimTimerListItemViewModels.Select(i => i.GetAimTimerItem()).ToList());
            AimTimerListItemViewModels.CollectionChanged += AimTimerItemViewModels_CollectionChanged;
            //_aimTimerNotificationService.OnStatusChanged += AimTimerNotificationService_OnStatusChanged;
            //_aimTimerNotificationService.Start();
            _messagingCenter.Subscribe <IAimTimerItem>(this, MessagingCenterMessages.AimTimerUpdated, OnItemUpdated);

            InitTimer();

            OnPropertyChanged(nameof(Title));
        }