共用方式為


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();
    }
}

適用於