From 4dd2b7274ea44869f9002f1feef31f68a3f20803 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Mon, 25 Apr 2022 11:16:01 +0200 Subject: [PATCH] Fix `StartTcpListener` method not stopping program if fails --- HyperbolicDownloader/Program.cs | 5 ++++- HyperbolicDownloaderApi/Managment/ApiManager.cs | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/HyperbolicDownloader/Program.cs b/HyperbolicDownloader/Program.cs index fb2199a..d87fa39 100644 --- a/HyperbolicDownloader/Program.cs +++ b/HyperbolicDownloader/Program.cs @@ -52,7 +52,10 @@ internal static class Program ConsoleExt.WriteLine($"The private port is: {ApiConfiguration.PrivatePort}", ConsoleColor.Green); Console.WriteLine("Starting TCP listener..."); - apiManager.StartTcpListener(); + if (!apiManager.StartTcpListener()) + { + Console.ReadLine(); + } Console.WriteLine("Starting broadcast listener..."); apiManager.StartBroadcastListener(); diff --git a/HyperbolicDownloaderApi/Managment/ApiManager.cs b/HyperbolicDownloaderApi/Managment/ApiManager.cs index aeb485d..1d3f806 100644 --- a/HyperbolicDownloaderApi/Managment/ApiManager.cs +++ b/HyperbolicDownloaderApi/Managment/ApiManager.cs @@ -115,7 +115,7 @@ public class ApiManager broadcastClient.OnBroadcastRecived += BroadcastClient_OnBroadcastRecived; } - public void StartTcpListener() + public bool StartTcpListener() { try { @@ -128,8 +128,10 @@ public class ApiManager catch (SocketException ex) { SendNotificationMessageNewLine($"An error occurred while starting the TCP listener! Error message: {ex.Message}", NotificationMessageType.Error); // net stop hens && net start hns - Console.ReadKey(); + return false; } + + return true; } private async void BroadcastClient_OnBroadcastRecived(object? sender, BroadcastRecivedEventArgs recivedEventArgs)