WebHostWindowsServiceExtensions.RunAsService(IWebHost) WebHostWindowsServiceExtensions.RunAsService(IWebHost) WebHostWindowsServiceExtensions.RunAsService(IWebHost) Method

Definition

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

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 IWebHost 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