WebHostWindowsServiceExtensions.RunAsService(IWebHost) Method

Definition

Runs the specified web application inside a Windows service and blocks until the service is stopped.

C#
public static void RunAsService (this Microsoft.AspNetCore.Hosting.IWebHost host);

Parameters

host
IWebHost

An instance of the IWebHost to host in the Windows service.

Examples

This example shows how to use RunAsService(IWebHost).

public class Program
{
    public static void Main(string[] args)
    {
        var config = WebHostConfiguration.GetDefault(args);

        var host = new WebHostBuilder()
            .UseConfiguration(config)
            .Build();

        // This call will block until the service is stopped.
        host.RunAsService();
    }
}

Applies to

Produk Versi
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0