WebHostWindowsServiceExtensions.RunAsService(IWebHost) 方法

定义

在 Windows 服务中运行指定的 Web 应用程序,并阻止,直到服务停止。

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)

参数

host
IWebHost

要托管在 Windows 服务中的 的实例 IWebHost

示例

此示例演示如何使用 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();
    }
}

适用于