Files
Wino-Mail/Wino.Core.UWP/Services/BackgroundTaskService.cs

32 lines
967 B
C#
Raw Normal View History

2024-08-09 01:24:55 +02:00
using Serilog;
2024-04-18 01:44:37 +02:00
using Windows.ApplicationModel.Background;
using Wino.Core.Domain.Interfaces;
namespace Wino.Core.UWP.Services
{
public class BackgroundTaskService : IBackgroundTaskService
{
2024-08-09 01:24:55 +02:00
private const string IsBackgroundTasksUnregisteredKey = nameof(IsBackgroundTasksUnregisteredKey);
2024-04-18 01:44:37 +02:00
private readonly IConfigurationService _configurationService;
public BackgroundTaskService(IConfigurationService configurationService)
{
_configurationService = configurationService;
}
public void UnregisterAllBackgroundTask()
{
2024-08-09 01:24:55 +02:00
if (_configurationService.Get<bool>(IsBackgroundTasksUnregisteredKey, false))
2024-04-18 01:44:37 +02:00
{
2024-08-09 01:24:55 +02:00
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
task.Value.Unregister(true);
}
2024-04-18 01:44:37 +02:00
2024-08-09 01:24:55 +02:00
Log.Information("Unregistered all background tasks.");
}
2024-04-18 01:44:37 +02:00
}
}
}