-Aggiunta configurazione di pubblicazione come servizio windows

This commit is contained in:
2025-06-22 15:58:59 +02:00
parent 33bd5e2bbf
commit 207d6fc845
3 changed files with 36 additions and 0 deletions
@@ -0,0 +1,31 @@
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}");
}
}
}
}
+1
View File
@@ -14,6 +14,7 @@
<ItemGroup>
<PackageReference Include="ExcelDataReader" Version="3.7.0" />
<PackageReference Include="ExcelDataReader.DataSet" Version="3.7.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="9.0.6" />
</ItemGroup>
</Project>
+4
View File
@@ -10,6 +10,7 @@ using CredentialManager;
using Data_Coupler.Services;
using System;
using System.Threading.Tasks;
using Data_Coupler.BackgrounServices;
// Registra il provider di encoding per ExcelDataReader (necessario per file .xls)
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
@@ -19,6 +20,8 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddWindowsService();
builder.Services.AddHostedService<BackgroundServices>();
// Add CredentialManager services
var contentRoot = builder.Environment.ContentRootPath;
@@ -32,6 +35,7 @@ builder.Services.AddHttpClient();
// Register Data Connection Factory
builder.Services.AddScoped<IDataConnectionFactory, DataConnectionFactory>();
builder.WebHost.UseUrls("http://*:7550");
var app = builder.Build();