When it can be usefull to use the `IWebHost.Start()` method?

Not all hosting is performed in a classic serving-pages-over-the-internet scenario. For example, you may want to serve content from your WPF app or a Windows service. In this situation you probably don't want the call to block - your app will have other things to do. For example, lets say you have a WPF app and you want to service content from it, you could simply extend the main method:

private IWebHost _webHost;

static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    //Create the host
    _webHost = WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .Build();

    //We want to start, not run because we need the rest of the app to run
    _webHost.Start();

    //Run the app as normal
    Application.Run(new MainForm());

    //We're back from the app now, we can stop the host
    //...
}

This is useful when you are testing your web service in the same process that is running the test suite.

For an example, you don't have to look any further than Microsoft's TestServer implementation. Within its constructor, it is calling IWebHost.StartAsync() instead of Run(). This allows the IWebHost to run on a non-blocking thread while your test suite runs requests against it, disposing of the TestServer when the test suite completes.

This may also be called explicitly for end-to-end tests where your service is getting requests indirectly from another service. For example, I have a service that is pushed messages from Google Cloud PubSub. So in my test suite I call Start() on my service's encapsulating IWebHost, send a message to the pubsub emulator running in a docker container, and that calls my test host. I verify the test host received requests as I expected, then I shut down the test host.