From b6655c930866fadf3275587f4c692aa658bd9b21 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期三, 24 六月 2020 10:57:07 +0800 Subject: [PATCH] 2020-06-24 1. 修改网络请求方法,改为HttpWebRequest支持自定义超时时间,默认10S。 2.后台回前台,超过20S断开远程重新连接。 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToSocket.cs | 62 ++++++++++++++++++------------- 1 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToSocket.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToSocket.cs index e7b626e..bb904ee 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToSocket.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToSocket.cs @@ -237,7 +237,7 @@ } } } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); @@ -246,6 +246,7 @@ }); } + private readonly object SendLocker = new object (); /// <summary> /// 鎺у埗鎵�鏈夌殑鐏� /// </summary> @@ -275,34 +276,43 @@ byte [] returnBytes = null; if (common.Type == DeviceType.LightEnergySocket) { new System.Threading.Thread (() => { - mSendCount++; - returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.LoopID, b, 0, 0 }); - if (showTip) { - if (returnBytes == null) { - Application.RunOnMainThread (() => { + try { + lock (SendLocker) { + mSendCount++; + } + //mSendCount++; + returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.LoopID, b, 0, 0 }); + if (showTip) { + if (returnBytes == null) { + Application.RunOnMainThread (() => { - var btnTip = new Button () { - Height = Application.GetRealHeight (140), - Text = common.Name + ErrorCode.ControlFailure, - BackgroundColor = 0xFFD7D7D7, - }; - MainPage.MainFrameLayout.AddChidren (btnTip); - btnTip.MouseUpEventHandler += (sender, e) => { - btnTip.RemoveFromParent (); - }; - - System.Threading.Tasks.Task.Run (() => { - System.Threading.Thread.Sleep (3000); - Application.RunOnMainThread (() => { + var btnTip = new Button () { + Height = Application.GetRealHeight (140), + Text = common.Name + ErrorCode.ControlFailure, + BackgroundColor = 0xFFD7D7D7, + }; + MainPage.MainFrameLayout.AddChidren (btnTip); + btnTip.MouseUpEventHandler += (sender, e) => { btnTip.RemoveFromParent (); - }); - }); + }; - }); + System.Threading.Tasks.Task.Run (() => { + System.Threading.Thread.Sleep (3000); + Application.RunOnMainThread (() => { + btnTip.RemoveFromParent (); + }); + }); + + }); + } + } + //mSendCount--; + } catch { } finally { + lock (SendLocker) { + mSendCount--; } } - mSendCount--; - }) { IsBackground = true}.Start(); + }) { IsBackground = true }.Start (); //绛夊緟100ms鍐嶅彂閫佺浜屼釜璁惧鏁版嵁 System.Threading.Thread.Sleep (100); @@ -316,7 +326,7 @@ System.Threading.Thread.Sleep (100); } } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); @@ -559,7 +569,7 @@ { if (isCheckIsReadingAll) { if (IsReadingAll && !isRead) { - Console.WriteLine ("IsLightReadingAll 璇诲彇涓�"); + Utlis.WriteLine ("IsLightReadingAll 璇诲彇涓�"); return; } } -- Gitblit v1.8.0