Back to Dotnet

PACKAGE

src/libraries/Microsoft.Extensions.Hosting.WindowsServices/src/PACKAGE.md

11.0.1001.7 KB
Original Source

About

Supports using Windows Services with the hosting infrastructure.

Key Features

  • Can configure a host to be a Windows Service.

How to Use

From a Worker Service app created using the Visual Studio template:

cs
IHost host = Host.CreateDefaultBuilder(args)
    .ConfigureServices(services =>
    {
        services.AddHostedService<Worker>();
    })
    // Configure as a Windows Service
    .UseWindowsService(options =>
    {
        options.ServiceName = "My Service";
    })
    .Build();

host.Run();

Main Types

The main types provided by this library are:

  • Microsoft.Extensions.Hosting.WindowsServiceLifetimeHostBuilderExtensions
  • Microsoft.Extensions.Hosting.WindowsServices.WindowsServiceLifetime

Additional Documentation

  • Microsoft.Extensions.Hosting
  • System.ServiceProcess.ServiceController

Feedback & Contributing

<!-- How to provide feedback on this package and contribute to it -->

Microsoft.Extensions.Hosting.WindowsServices is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.