private async Task DoWorkAsync(CancellationToken ct = default(CancellationToken)) { try { while (_listener.IsListening) { if (ct.IsCancellationRequested) { _listener.Stop(); break; } HttpListenerContext context = await _listener.GetContextAsync(); string localUrl = $"{LocalHost}:{LocalPort}"; string remoteUrl = $"{RemoteHost}:{RemotePort}"; _remoteUriService.GetResponseAsync(context, localUrl, remoteUrl, ct).DoNotWait(); } } catch (Exception ex) { if (Servers.ContainsKey(RemotePort)) { // Log only if we expect this web server to be running and it fails. _log.WriteLine(LogVerbosity.Minimal, MessageCategory.Error, Resources.Error_RemoteWebServerFailed.FormatInvariant(_name, ex.Message)); _console.WriteErrorLine(Resources.Error_RemoteWebServerFailed.FormatInvariant(_name, ex.Message)); } } finally { Stop(RemotePort); } }
private async Task DoWorkAsync(CancellationToken ct) { while (_listener.IsListening) { if (ct.IsCancellationRequested) { _listener.Stop(); break; } HttpListenerContext context = await _listener.GetContextAsync(); string localUrl = $"{LocalHost}:{LocalPort}"; string remoteUrl = $"{RemoteHost}:{RemotePort}"; await _remoteUriService.GetResponseAsync(context, localUrl, remoteUrl, ct); } }