Exemplo n.º 1
0
 protected sealed override void OnStop()
 {
     _stopRequestedByWindows = true;
     OnStopping();
     try
     {
         _host.StopAsync().GetAwaiter().GetResult();
     }
     finally
     {
         _host.Dispose();
         OnStopped();
     }
 }
Exemplo n.º 2
0
        static async Task WaitForTokenShutdownAsync(this IGameHost host, CancellationToken token)
        {
            var applicationLifetime = host.Services.GetService <IHostApplicationLifetime>();

            token.Register(state =>
            {
                ((IHostApplicationLifetime)state).StopApplication();
            },
                           applicationLifetime);

            var waitForStop = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);

            applicationLifetime.ApplicationStopping.Register(obj =>
            {
                var tcs = (TaskCompletionSource <object>)obj;
                tcs.TrySetResult(null);
            }, waitForStop);

            await waitForStop.Task;

            // GameHost will use its default ShutdownTimeout if none is specified.
            await host.StopAsync();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Attempts to gracefully stop the host with the given timeout.
 /// </summary>
 /// <param name="host"></param>
 /// <param name="timeout">The timeout for stopping gracefully. Once expired the
 /// server may terminate any remaining active connections.</param>
 /// <returns></returns>
 public static Task StopAsync(this IGameHost host, TimeSpan timeout) =>
 host.StopAsync(new CancellationTokenSource(timeout).Token);