Update Async

This commit is contained in:
ChsBuffer
2021-06-26 16:47:46 +08:00
parent 62dc9166ce
commit 58c5f9d086
4 changed files with 30 additions and 30 deletions

View File

@@ -13,7 +13,6 @@ namespace Netch.Controllers
{
public static Mode? Mode;
/// TCP or Both Server
public static Server? Server;
private static Server? _udpServer;
@@ -50,11 +49,6 @@ namespace Netch.Controllers
/// <returns>是否启动成功</returns>
/// <exception cref="MessageException"></exception>
public static async Task StartAsync(Server server, Mode mode)
{
await Task.Run(() => Start(server, mode));
}
public static void Start(Server server, Mode mode)
{
Log.Information("启动主控制器: {Server} {Mode}", $"{server.Type}", $"[{(int)mode.Type}]{mode.Remark}");
Server = server;
@@ -81,7 +75,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
Stop();
await StopAsync();
switch (e)
{
@@ -131,21 +125,13 @@ namespace Netch.Controllers
}
public static async Task StopAsync()
{
await Task.Run(Stop);
}
/// <summary>
/// 停止
/// </summary>
public static void Stop()
{
if (_serverController == null && ModeController == null)
return;
StatusPortInfoText.Reset();
_ = Task.Run(() => NTTController.Stop());
Task.Run(() => NTTController.Stop()).Forget();
var tasks = new[]
{
@@ -155,7 +141,7 @@ namespace Netch.Controllers
try
{
Task.WaitAll(tasks);
await Task.WhenAll(tasks);
}
catch (Exception e)
{