From 6e7d363e82b03f7b99271d8e4d516f2d8e427ca3 Mon Sep 17 00:00:00 2001 From: zs <zhousong@weben-smart.com> Date: 周四, 21 11月 2024 09:29:33 +0800 Subject: [PATCH] 关闭结束所有进程 --- DataCapture_MA/Form1.cs | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/DataCapture_MA/Form1.cs b/DataCapture_MA/Form1.cs index f693d48..d568930 100644 --- a/DataCapture_MA/Form1.cs +++ b/DataCapture_MA/Form1.cs @@ -22,6 +22,7 @@ { public partial class CaptrueForm : Form { + private CancellationTokenSource _cts = new CancellationTokenSource(); bool RunningFlag = false; Socket skt = WZ.Useful.Commons.NetworkUtil.CreateUdpSocket(); EndPoint RemotePoint = null; @@ -74,8 +75,24 @@ // 鍒犻櫎涓�涓湀鍓嶇殑鏁版嵁 new Thread(AutoDeleteHistoryDate.Handler).Start(); + + this.FormClosing += CaptrueForm_FormClosing; + this.FormClosed += CaptrueForm_FormClosed; + } + private void CaptrueForm_FormClosing(object sender, FormClosingEventArgs e) + { + // 閫氱煡鍚庡彴浠诲姟鍙栨秷 + _cts.Cancel(); + + // 纭繚浠诲姟瀹屾垚 + Task.WaitAll(Task.WhenAll()); } + private void CaptrueForm_FormClosed(object sender, FormClosedEventArgs e) + { + // 纭繚绋嬪簭閫�鍑� + Environment.Exit(0); + } public static void CreateShortcut(string shortcutName, string targetPath, string startupPath) { @@ -89,7 +106,7 @@ shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); shortcut.Save(); } - + private void ReceiveHandle() { //鎺ユ敹鏁版嵁澶勭悊绾跨▼ -- Gitblit v1.9.3