From 2d5cd35af7437ad4015d38594d8c721dc6166b11 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期二, 29 八月 2023 09:22:38 +0800
Subject: [PATCH] Merge branch 'wjc' of http://59.41.255.150:6688/r/~wxr/OnPro into wjc

---
 HDL_ON/DAL/DriverLayer/UdpSocket.cs |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/UdpSocket.cs b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
index 36637f9..df9662a 100644
--- a/HDL_ON/DAL/DriverLayer/UdpSocket.cs
+++ b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
@@ -29,14 +29,14 @@
         {
 			if (IsRunning)
 			{
-                if (port == Port)
+				if (port == Port)
                 {
                     return;
-                }
+				}
                 else
                 {
                     busSocket.Close();
-                }
+				}
             }
 			if (port != 0)
 				Port = port;
@@ -49,6 +49,7 @@
 				busSocket.Bind(new IPEndPoint(IPAddress.Any, Port));
 
 				busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188")));
+				relinkCount = 0;
 			}
 			catch (Exception ex){
 				MainPage.Log ($"udp port bind error : {ex.Message}");
@@ -67,6 +68,10 @@
 		/// </summary>
 		public void Stop()
 		{
+			if(busSocket == null)
+            {
+				return;
+            }
 			if (!IsRunning)
 			{
 				return;
@@ -74,6 +79,7 @@
 			try
 			{
 				busSocket.Close();
+				relinkCount = 0;
 			}
 			catch { }
 			busSocket = null;
@@ -100,6 +106,10 @@
 			{
 				return;
 			}
+			if(busSocket == null)
+            {
+				return;
+            }
 
             try {
                 Packet packet = new Packet ();
@@ -107,10 +117,21 @@
             } 
             catch (Exception e) {
                 System.Threading.Thread.Sleep (1);
-                asyncBeginReceive ();
+                Console.WriteLine("asyncBeginReceive " + relinkCount	);
+				if (relinkCount == 0)
+				{
+					relinkCount = 1;
+					asyncBeginReceive();
+				}
                 Console.WriteLine($"asyncBeginReceive {e.Message}");
             } 
 		}
+		/// <summary>
+        /// 閲嶈繛娆℃暟
+        /// </summary>
+		private int relinkCount = 0;
+
+
 
 		/// <summary>
 		/// 寮傛鎺ユ敹鏁版嵁缁撴潫

--
Gitblit v1.8.0