Skip to content

Commit

Permalink
Merge pull request #227 from ProfessionalCSharp/windowsservices-dotnet8
Browse files Browse the repository at this point in the history
Update the Windows Services samples to .NET 8
  • Loading branch information
christiannagel authored Oct 25, 2024
2 parents 620bc92 + 1fc9930 commit eb2fb17
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-SimpleWorkerService-39D11380-59B5-4EE1-B441-64FB46CAE1C9</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0-preview.1.22076.8" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1" />
</ItemGroup>
</Project>
13 changes: 3 additions & 10 deletions 5_More/WindowsServices/SimpleWorkerService/Worker.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
namespace SimpleWorkerService;

public class Worker : BackgroundService
public class Worker(ILogger<Worker> logger) : BackgroundService
{
private readonly ILogger<Worker> _logger;

public Worker(ILogger<Worker> 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);
}
}
Expand Down

0 comments on commit eb2fb17

Please sign in to comment.