protected override Task ExecuteAsync(CancellationToken stoppingToken) { var serviceDefinition = Echo.BindService(new EchoService()) .Intercept(new ServerTracingInterceptor(new ServerTracingInterceptorOptions())); var server = new Server { Ports = { new ServerPort("localhost", Program.GrpcServicePort, ServerCredentials.Insecure) }, Services = { serviceDefinition }, }; server.Start(); var tcs = new TaskCompletionSource <bool>(); var tokenRegistration = stoppingToken.Register( async() => { await server.ShutdownAsync().ConfigureAwait(false); tcs.SetResult(true); }); return(tcs.Task.ContinueWith(antecedent => tokenRegistration.Dispose())); }