WebHostWindowsServiceExtensions.RunAsService(IWebHost) Method

Definition

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

public:
[System::Runtime::CompilerServices::Extension]
 static void RunAsService(Microsoft::AspNetCore::Hosting::IWebHost ^ host);
public static void RunAsService (this Microsoft.AspNetCore.Hosting.IWebHost host);
static member RunAsService : Microsoft.AspNetCore.Hosting.IWebHost -> unit
<Extension()>
Public Sub RunAsService (host As IWebHost)

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