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 | 23 ++++++++++++++++++++--- 1 files changed, 20 insertions(+), 3 deletions(-) diff --git a/DataCapture_MA/Form1.cs b/DataCapture_MA/Form1.cs index d025d3d..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; @@ -52,10 +53,9 @@ if (!foundTargetSubnet && ipSelect.Items.Count > 0) { - MessageBox.Show($"鏈壘鍒扮綉娈典负 {targetSubnet} 鐨処P鍦板潃锛屽皢榛樿閫変腑绗竴涓狪P銆�", "鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Information); + //MessageBox.Show($"鏈壘鍒扮綉娈典负 {targetSubnet} 鐨処P鍦板潃锛屽皢榛樿閫変腑绗竴涓狪P銆�", "鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Information); ipSelect.SelectedIndex = 0; } - to_ipTxt.Text = ipSelect.SelectedItem?.ToString(); // 鍒濆鍖� AutoMapper @@ -71,11 +71,28 @@ CreateShortcut(shortcutName, targetPath, startupPath); // 鍒涘缓蹇嵎鏂瑰紡 StartReceive(); // 鍚姩绋嬪簭 + CreateDatabase(); // 鍒濆鍖栨暟鎹簱 // 鍒犻櫎涓�涓湀鍓嶇殑鏁版嵁 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