Exemple #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await _messagingHost.StartAsync(stoppingToken);

            await stoppingToken.WhenCanceled();

            await _messagingHost.StopAsync();
        }
Exemple #2
0
 /// <summary>
 /// Attempts to gracefully stop the host with the given timeout.
 /// </summary>
 /// <param name="host">The <see cref="IMessagingHost"/> to stop.</param>
 /// <param name="timeout">The timeout for stopping gracefully. Once expired the
 /// server may terminate any remaining active connections.</param>
 /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
 public static async Task StopAsync(this IMessagingHost host, TimeSpan timeout)
 {
     using CancellationTokenSource cts = new CancellationTokenSource(timeout);
     await host.StopAsync(cts.Token).ConfigureAwait(false);
 }