From 729e72bd48206e31801e57805bc9a5c48719965f Mon Sep 17 00:00:00 2001 From: waldekmastykarz Date: Wed, 20 Nov 2024 19:51:35 +0100 Subject: [PATCH] Adds handling exception when stopping proxy. Closes #944 --- dev-proxy/ProxyEngine.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/dev-proxy/ProxyEngine.cs b/dev-proxy/ProxyEngine.cs index 2703a90c..86ac8152 100755 --- a/dev-proxy/ProxyEngine.cs +++ b/dev-proxy/ProxyEngine.cs @@ -160,19 +160,26 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) } _pluginEvents.AfterRequestLog += AfterRequestLogAsync; - while (!stoppingToken.IsCancellationRequested && _proxyServer.ProxyRunning) + + try { - while (!Console.KeyAvailable) + while (!stoppingToken.IsCancellationRequested && _proxyServer.ProxyRunning) { - await Task.Delay(10, stoppingToken); - } - // we need this check or proxy will fail with an exception - // when run for example in VSCode's integrated terminal - if (isInteractive) - { - await ReadKeysAsync(); + while (!Console.KeyAvailable) + { + await Task.Delay(10, stoppingToken); + } + // we need this check or proxy will fail with an exception + // when run for example in VSCode's integrated terminal + if (isInteractive) + { + await ReadKeysAsync(); + } } } + catch (TaskCanceledException) + { + } } private void FirstRunSetup()