zs
2024-11-21 6e7d363e82b03f7b99271d8e4d516f2d8e427ca3
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()
        {
            //接收数据处理线程