32 lines
955 B
C#
32 lines
955 B
C#
using System;
|
|
|
|
namespace Data_Coupler.BackgrounServices;
|
|
|
|
public class BackgroundServices : BackgroundService
|
|
{
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
try
|
|
{
|
|
// Qui puoi inserire il codice che vuoi eseguire in background
|
|
// Ad esempio, puoi chiamare un metodo per eseguire operazioni periodiche
|
|
|
|
// Simula un'attività di lunga durata
|
|
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
// Gestisci l'eccezione se il task viene cancellato
|
|
break;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Gestisci altre eccezioni
|
|
Console.WriteLine($"Errore: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|