diff --git a/src/components/tbc.core/Socket/SocketServer.cs b/src/components/tbc.core/Socket/SocketServer.cs index 01d59db..8eeff39 100644 --- a/src/components/tbc.core/Socket/SocketServer.cs +++ b/src/components/tbc.core/Socket/SocketServer.cs @@ -73,7 +73,7 @@ public async Task Run(CancellationToken ct = default) .ContinueWith(t => #pragma warning restore CS4014 { - _log("Request loop terminated:"); + _log("Request loop terminated: "); _log(t.Exception?.ToString() ?? "no exception"); _finished = true; }); @@ -87,20 +87,15 @@ private async Task RunRequestLoop(CancellationToken ct = default) _log($"receive result: {receiveResult}"); if (receiveResult.Outcome == ReceiveResultOutcome.Disconnect) - await Terminate(); - } - } - - private async Task Terminate() - { - if (_onDisconnect is { } od) - await od.Invoke(); + { + if (_onDisconnect is { } od) + await od.Invoke(); - throw new FinishedException(); + break; + } + } } - public class FinishedException : Exception {} - private async Task ReceiveAndHandle(CancellationToken ct = default) { var receiveResult = await Receive(ct); diff --git a/src/components/tbc.host/Extensions/HelpfulExtensions.cs b/src/components/tbc.host/Extensions/HelpfulExtensions.cs index a6024dd..3cb924a 100644 --- a/src/components/tbc.host/Extensions/HelpfulExtensions.cs +++ b/src/components/tbc.host/Extensions/HelpfulExtensions.cs @@ -17,7 +17,10 @@ public static class HelpfulExtensions Task.Run(async () => { while (true) - await @do(); + { + try { await @do(); } + catch (Exception ex) { Console.WriteLine(ex); } + } }); public static JsonSerializerSettings NaiveCloneSerialiserSettings = new JsonSerializerSettings diff --git a/src/components/tbc.target/TargetServer.cs b/src/components/tbc.target/TargetServer.cs index 980f3da..0a1a0ca 100644 --- a/src/components/tbc.target/TargetServer.cs +++ b/src/components/tbc.target/TargetServer.cs @@ -29,7 +29,6 @@ public async Task Run(IReloadManager reloadManager, Action log = null) log ??= Console.WriteLine; var listener = new TcpListener(IPAddress.Any, Configuration.ListenPort); - var handler = new AssemblyLoaderService(Configuration, reloadManager, log); listener.Start(); @@ -41,6 +40,7 @@ public async Task Run(IReloadManager reloadManager, Action log = null) try { + var handler = new AssemblyLoaderService(Configuration, reloadManager, log); var socketServer = new SocketServer(connection, handler, "client", log); await socketServer.Run(); }