static async Task RunAsync(this IGameHost host, CancellationToken token, string startupMessage) { try { await host.StartAsync(token); var hostingEnvironment = host.Services.GetService <IHostEnvironment>(); var options = host.Services.GetRequiredService <GameHostOptions>(); if (!options.SuppressStatusMessages) { Console.WriteLine($"Hosting environment: {hostingEnvironment.EnvironmentName}"); Console.WriteLine($"Content root path: {hostingEnvironment.ContentRootPath}"); var serverAddresses = host.ServerFeatures?.Get <IServerAddressesFeature>()?.Addresses; if (serverAddresses != null) { foreach (var address in serverAddresses) { Console.WriteLine($"Now listening on: {address}"); } } if (!string.IsNullOrEmpty(startupMessage)) { Console.WriteLine(startupMessage); } } await host.WaitForTokenShutdownAsync(token); } finally { #if !NET2 if (host is IAsyncDisposable asyncDisposable) { await asyncDisposable.DisposeAsync().ConfigureAwait(false); } else #endif host.Dispose(); } }