From ef922ef4a263b481b982f02bcd4896faa71bf7cb Mon Sep 17 00:00:00 2001 From: milimoe <110188673+milimoe@users.noreply.github.com> Date: Sat, 30 Sep 2023 12:29:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/RunTimeController.cs | 2 +- .../Library/Component/ShowMessage.cs | 2 +- FunGame.Desktop/UI/Login/ForgetPassword.cs | 2 +- FunGame.Desktop/UI/Login/Login.cs | 2 +- FunGame.Desktop/UI/Main/Main.cs | 87 +++++++++---------- FunGame.Desktop/UI/Register/Register.cs | 4 +- 6 files changed, 46 insertions(+), 53 deletions(-) diff --git a/FunGame.Desktop/Controller/RunTimeController.cs b/FunGame.Desktop/Controller/RunTimeController.cs index b8510d5..a493f57 100644 --- a/FunGame.Desktop/Controller/RunTimeController.cs +++ b/FunGame.Desktop/Controller/RunTimeController.cs @@ -129,7 +129,7 @@ namespace Milimoe.FunGame.Desktop.Controller { try { - Core.Api.Utility.TaskUtility.StartAndAwaitTask(async () => await LoginController.LoginAccountAsync(Username, Password, AutoKey)); + Core.Api.Utility.TaskUtility.NewTask(async () => await LoginController.LoginAccountAsync(Username, Password, AutoKey)); } catch (Exception e) { diff --git a/FunGame.Desktop/Library/Component/ShowMessage.cs b/FunGame.Desktop/Library/Component/ShowMessage.cs index caa1055..59c04dc 100644 --- a/FunGame.Desktop/Library/Component/ShowMessage.cs +++ b/FunGame.Desktop/Library/Component/ShowMessage.cs @@ -113,7 +113,7 @@ namespace Milimoe.FunGame.Desktop.Library.Component } if (AutoClose > 0) { - TaskUtility.StartAndAwaitTask(async () => + TaskUtility.NewTask(async () => { string msg = MsgText.Text; int s = AutoClose; diff --git a/FunGame.Desktop/UI/Login/ForgetPassword.cs b/FunGame.Desktop/UI/Login/ForgetPassword.cs index 6bed436..c26d2df 100644 --- a/FunGame.Desktop/UI/Login/ForgetPassword.cs +++ b/FunGame.Desktop/UI/Login/ForgetPassword.cs @@ -19,7 +19,7 @@ namespace Milimoe.FunGame.Desktop.UI private void FindPassword_Click(object sender, EventArgs e) { - TaskUtility.StartAndAwaitTask(async () => + TaskUtility.NewTask(async () => { if (RunTime.Socket != null) { diff --git a/FunGame.Desktop/UI/Login/Login.cs b/FunGame.Desktop/UI/Login/Login.cs index 29c70b8..ed33a06 100644 --- a/FunGame.Desktop/UI/Login/Login.cs +++ b/FunGame.Desktop/UI/Login/Login.cs @@ -69,7 +69,7 @@ namespace Milimoe.FunGame.Desktop.UI { GoToLogin.Enabled = false; bool result = false; - TaskUtility.StartAndAwaitTask(async () => + TaskUtility.NewTask(async () => { result = await Login_Handler(); }).OnCompleted(() => diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs index 096cb54..b2cbe14 100644 --- a/FunGame.Desktop/UI/Main/Main.cs +++ b/FunGame.Desktop/UI/Main/Main.cs @@ -56,7 +56,7 @@ namespace Milimoe.FunGame.Desktop.UI // 创建RunTime RunTime.Controller = new RunTimeController(this); // 窗口句柄创建后,进行委托 - TaskUtility.StartAndAwaitTask(() => + TaskUtility.NewTask(() => { while (true) { @@ -724,7 +724,7 @@ namespace Milimoe.FunGame.Desktop.UI if (isLeave) TalkText_Leave(); // 回车不离开焦点 if (MainController != null && Usercfg.LoginUser.Id != 0 && !SwitchTalkMessage(text)) { - TaskUtility.StartAndAwaitTask(async () => + TaskUtility.NewTask(async () => { if (!await InvokeController_SendTalk(" [ " + Usercfg.LoginUserName + " ] 说: " + text)) { @@ -866,7 +866,7 @@ namespace Milimoe.FunGame.Desktop.UI private void ExitFunGame() { bool exit = false; - TaskUtility.StartAndAwaitTask(() => + TaskUtility.NewTask(() => { if (ShowMessage(ShowMessageType.OKCancel, "你确定关闭游戏?", "退出") == MessageResult.OK) { @@ -893,7 +893,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void Exit_Click(object sender, EventArgs e) { - TaskUtility.StartAndAwaitTask(ExitFunGame); + TaskUtility.NewTask(ExitFunGame); } /// @@ -960,7 +960,7 @@ namespace Milimoe.FunGame.Desktop.UI ShowMessage(ShowMessageType.Warning, "请勾选你要创建的房间类型!"); return; } - TaskUtility.StartAndAwaitTask(() => CreateRoom_Handler(Config.FunGame_GameMode, password)); + TaskUtility.NewTask(() => CreateRoom_Handler(Config.FunGame_GameMode, password)); } /// @@ -973,7 +973,7 @@ namespace Milimoe.FunGame.Desktop.UI string roomid = Usercfg.InRoom.Roomid; bool isMaster = Usercfg.InRoom.RoomMaster?.Id == Usercfg.LoginUser.Id; bool result = false; - TaskUtility.StartAndAwaitTask(async () => + TaskUtility.NewTask(async () => { if (await InvokeController_QuitRoom(Usercfg.InRoom, isMaster)) { @@ -1017,7 +1017,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void QueryRoom_Click(object sender, EventArgs e) { - TaskUtility.StartAndAwaitTask(async () => await JoinRoom(false, RoomText.Text)); + TaskUtility.NewTask(async () => await JoinRoom(false, RoomText.Text)); } /// @@ -1027,7 +1027,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void Logout_Click(object sender, EventArgs e) { - TaskUtility.StartAndAwaitTask(async () => + TaskUtility.NewTask(async () => { if (ShowMessage(ShowMessageType.OKCancel, "你确定要退出登录吗?", "退出登录") == MessageResult.OK) { @@ -1069,7 +1069,7 @@ namespace Milimoe.FunGame.Desktop.UI { if (RoomList.SelectedItem != null) { - TaskUtility.StartAndAwaitTask(async () => await JoinRoom(true, RoomList.SelectedItem.ToString() ?? "")); + TaskUtility.NewTask(async () => await JoinRoom(true, RoomList.SelectedItem.ToString() ?? "")); } } @@ -1141,7 +1141,7 @@ namespace Milimoe.FunGame.Desktop.UI if (e.KeyCode.Equals(Keys.Enter)) { // 按下回车加入房间 - TaskUtility.StartAndAwaitTask(async () => await JoinRoom(false, RoomText.Text)); + TaskUtility.NewTask(async () => await JoinRoom(false, RoomText.Text)); } } @@ -1219,7 +1219,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void RefreshRoomList_Click(object sender, EventArgs e) { - TaskUtility.StartAndAwaitTask(async () => + TaskUtility.NewTask(async () => { if (MainController != null) { @@ -1284,7 +1284,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void SucceedLoginEvent(object sender, GeneralEventArgs e) { - TaskUtility.StartAndAwaitTask(SucceedLoginEvent_Handler); + TaskUtility.NewTask(SucceedLoginEvent_Handler); } /// @@ -1374,10 +1374,10 @@ namespace Milimoe.FunGame.Desktop.UI GameInfo.Clear(); break; case Constant.FunGame_CreateMix: - TaskUtility.StartAndAwaitTask(() => CreateRoom_Handler(GameMode.Mix)); + TaskUtility.NewTask(() => CreateRoom_Handler(GameMode.Mix)); break; case Constant.FunGame_CreateTeam: - TaskUtility.StartAndAwaitTask(() => CreateRoom_Handler(GameMode.Team)); + TaskUtility.NewTask(() => CreateRoom_Handler(GameMode.Team)); break; case Constant.FunGame_StartGame: break; @@ -1412,7 +1412,7 @@ namespace Milimoe.FunGame.Desktop.UI { // 先退出登录再断开连接 bool SuccessLogOut = false; - TaskUtility.StartAndAwaitTask(async () => + TaskUtility.NewTask(async () => { if (await LogOut()) SuccessLogOut = true; }).OnCompleted(() => @@ -1481,7 +1481,7 @@ namespace Milimoe.FunGame.Desktop.UI ConnectResult result = ConnectResult.CanNotConnect; - TaskUtility.StartAndAwaitTask(() => + TaskUtility.NewTask(() => { OnBeforeConnectEvent(this, EventArgs); RunTime.PluginLoader?.OnBeforeConnectEvent(this, EventArgs); @@ -1522,48 +1522,42 @@ namespace Milimoe.FunGame.Desktop.UI public void InvokeController_Disconnect() { GeneralEventArgs EventArgs = new(); + bool result = false; - try + TaskUtility.NewTask(async () => { - bool result = false; + OnBeforeDisconnectEvent(this, EventArgs); + RunTime.PluginLoader?.OnBeforeDisconnectEvent(this, EventArgs); + if (EventArgs.Cancel) return; - TaskUtility.StartAndAwaitTask(async () => + if (Usercfg.LoginUser.Id != 0) { - OnBeforeDisconnectEvent(this, EventArgs); - if (EventArgs.Cancel) return; - RunTime.PluginLoader?.OnBeforeDisconnectEvent(this, EventArgs); - if (EventArgs.Cancel) return; + await LogOut(); + } - if (Usercfg.LoginUser.Id != 0) - { - await LogOut(); - } - - result = RunTime.Controller?.Disconnect() ?? false; - }).OnCompleted(() => + result = RunTime.Controller?.Disconnect() ?? false; + }).OnCompleted(() => + { + if (result) { - if (result) - { - OnSucceedDisconnectEvent(this, EventArgs); - RunTime.PluginLoader?.OnSucceedDisconnectEvent(this, EventArgs); - } - else - { - OnFailedDisconnectEvent(this, EventArgs); - RunTime.PluginLoader?.OnFailedDisconnectEvent(this, EventArgs); - } - OnAfterDisconnectEvent(this, EventArgs); - RunTime.PluginLoader?.OnAfterDisconnectEvent(this, EventArgs); - }); - } - catch (Exception e) + OnSucceedDisconnectEvent(this, EventArgs); + RunTime.PluginLoader?.OnSucceedDisconnectEvent(this, EventArgs); + } + else + { + OnFailedDisconnectEvent(this, EventArgs); + RunTime.PluginLoader?.OnFailedDisconnectEvent(this, EventArgs); + } + OnAfterDisconnectEvent(this, EventArgs); + RunTime.PluginLoader?.OnAfterDisconnectEvent(this, EventArgs); + }).OnError(e => { GetMessage(e.GetErrorInfo(), TimeType.None); OnFailedDisconnectEvent(this, EventArgs); RunTime.PluginLoader?.OnFailedDisconnectEvent(this, EventArgs); OnAfterDisconnectEvent(this, EventArgs); RunTime.PluginLoader?.OnAfterDisconnectEvent(this, EventArgs); - } + }); } /// @@ -1668,7 +1662,6 @@ namespace Milimoe.FunGame.Desktop.UI try { OnBeforeCreateRoomEvent(this, EventArgs); - if (EventArgs.Cancel) return room; RunTime.PluginLoader?.OnBeforeCreateRoomEvent(this, EventArgs); if (EventArgs.Cancel) return room; diff --git a/FunGame.Desktop/UI/Register/Register.cs b/FunGame.Desktop/UI/Register/Register.cs index bb8aa81..b35015a 100644 --- a/FunGame.Desktop/UI/Register/Register.cs +++ b/FunGame.Desktop/UI/Register/Register.cs @@ -115,14 +115,14 @@ namespace Milimoe.FunGame.Desktop.UI { string username = ((RegisterEventArgs)e).Username; string password = ((RegisterEventArgs)e).Password; - TaskUtility.StartAndAwaitTask(async () => await LoginController.LoginAccountAsync(username, password, encrypt: false)); + TaskUtility.NewTask(async () => await LoginController.LoginAccountAsync(username, password, encrypt: false)); RunTime.Login?.Close(); } private void RegButton_Click(object sender, EventArgs e) { RegButton.Enabled = false; - TaskUtility.StartAndAwaitTask(async () => + TaskUtility.NewTask(async () => { if (!await Reg_Handler()) RegButton.Enabled = true; else Close();