From 1fc99309f18fcd8f316e2c0c5f6e7177d13b510b Mon Sep 17 00:00:00 2001 From: Christian Nagel Date: Fri, 25 Oct 2024 21:27:33 +0200 Subject: [PATCH] update windows service to .net 8 --- .../ASPNETCoreWindowsService.csproj | 6 +++--- .../SimpleWorkerService/SimpleWorkerService.csproj | 8 ++++---- .../WindowsServices/SimpleWorkerService/Worker.cs | 13 +++---------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/5_More/WindowsServices/ASPNETCoreWindowsService/ASPNETCoreWindowsService.csproj b/5_More/WindowsServices/ASPNETCoreWindowsService/ASPNETCoreWindowsService.csproj index 7f094176..f261306b 100644 --- a/5_More/WindowsServices/ASPNETCoreWindowsService/ASPNETCoreWindowsService.csproj +++ b/5_More/WindowsServices/ASPNETCoreWindowsService/ASPNETCoreWindowsService.csproj @@ -1,14 +1,14 @@  - net6.0-windows + net8.0-windows enable enable - - + + diff --git a/5_More/WindowsServices/SimpleWorkerService/SimpleWorkerService.csproj b/5_More/WindowsServices/SimpleWorkerService/SimpleWorkerService.csproj index 2129feec..06825155 100644 --- a/5_More/WindowsServices/SimpleWorkerService/SimpleWorkerService.csproj +++ b/5_More/WindowsServices/SimpleWorkerService/SimpleWorkerService.csproj @@ -1,14 +1,14 @@ - + - net7.0 + net8.0 enable enable dotnet-SimpleWorkerService-39D11380-59B5-4EE1-B441-64FB46CAE1C9 - - + + diff --git a/5_More/WindowsServices/SimpleWorkerService/Worker.cs b/5_More/WindowsServices/SimpleWorkerService/Worker.cs index 104da3ae..e54fb924 100644 --- a/5_More/WindowsServices/SimpleWorkerService/Worker.cs +++ b/5_More/WindowsServices/SimpleWorkerService/Worker.cs @@ -1,22 +1,15 @@ namespace SimpleWorkerService; -public class Worker : BackgroundService +public class Worker(ILogger logger) : BackgroundService { - private readonly ILogger _logger; - - public Worker(ILogger logger, IHostEnvironment environment) - { - _logger = logger; - } - protected override async Task ExecuteAsync(CancellationToken stoppingToken) { string[] args = Environment.GetCommandLineArgs(); - _logger.LogInformation("command line args: {args}", string.Join(" ", args)); + logger.LogInformation("command line args: {args}", string.Join(" ", args)); while (!stoppingToken.IsCancellationRequested) { - _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); + logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); await Task.Delay(10000, stoppingToken); } }