diff --git a/PrimaryFormParts/PrimaryForm.SequenceManager.cs b/PrimaryFormParts/PrimaryForm.SequenceManager.cs index a8c2da5..7cedb26 100644 --- a/PrimaryFormParts/PrimaryForm.SequenceManager.cs +++ b/PrimaryFormParts/PrimaryForm.SequenceManager.cs @@ -15,6 +15,7 @@ namespace DualScreenDemo { if (currentSequence[currentSequence.Count - 1] != correctSequence[currentSequence.Count - 1]) { + Console.WriteLine(currentSequence[currentSequence.Count - 1] +" 比對 " + correctSequence[currentSequence.Count - 1] +" 順序錯誤,重置序列"); // 順序錯誤,重置序列 currentSequence.Clear(); return; @@ -26,16 +27,23 @@ namespace DualScreenDemo { try { - // 使用 Windows 命令關機 - System.Diagnostics.Process.Start("shutdown", "/s /t 0"); + // ✅ 這行要在主執行緒執行,避免 UI 錯誤 + Cursor.Show(); + + Console.WriteLine("使用 Windows 命令關機"); + + // ✅ 關機動作移到背景執行緒 + new System.Threading.Thread(() => + { + System.Diagnostics.Process.Start("shutdown", "/s /t 0"); + }).Start(); } catch (Exception ex) { MessageBox.Show($"關機失敗: {ex.Message}"); - // 如果關機失敗,退出程式 - Application.Exit(); } } + } } } diff --git a/Program.cs b/Program.cs index eeaff67..79238c6 100644 --- a/Program.cs +++ b/Program.cs @@ -17,8 +17,15 @@ namespace DualScreenDemo [STAThread] static void Main() { + Console.WriteLine("隱藏滑鼠游標"); + Cursor.Hide(); + AppDomain.CurrentDomain.ProcessExit += (s, e) => + { + Cursor.Show(); + }; + Console.WriteLine("正在與中控取得聯繫"); - var sender = new HeartbeatSender.heartbeatSender("http://zqd.superstar.dnsnet.cc/api/room/receiveRegister"); + var sender = new HeartbeatSender.heartbeatSender(); // 同步呼叫非同步登入取得 token bool loginSuccess = sender.LoginAndGetTokenAsync().GetAwaiter().GetResult(); @@ -181,7 +188,7 @@ namespace DualScreenDemo { if (primaryForm.videoPlayerForm == null) { - var filePath = @"C:\\video\\100015-周杰倫&aMei-不該-國語-vL-100-11000001.mpg"; + var filePath = @"D:\\video\\100015-周杰倫&aMei-不該-國語-vL-100-11000001.mpg"; if (File.Exists(filePath)) { Screen secondaryScreen = Screen.AllScreens.FirstOrDefault(s => !s.Primary);