| | |
| | | public partial class RGBPage |
| | | { |
| | | /// <summary> |
| | | /// 通知更新界面的时间 |
| | | /// </summary> |
| | | DateTime notiyUpdateTime = DateTime.MinValue; |
| | | System.Threading.Thread updateUiThread; |
| | | object lockObj = new object(); |
| | | |
| | | public override void RemoveFromParent() |
| | | { |
| | | bodyView = null; |
| | | base.RemoveFromParent(); |
| | | } |
| | | /// <summary> |
| | | /// 更新功能状态 |
| | | /// </summary> |
| | | public static void UpdataStates(Function updateTemp) |
| | | { |
| | | if(bodyView == null) |
| | | { |
| | | return; |
| | | } |
| | | lock (bodyView.lockObj) |
| | | { |
| | | MainPage.Log($"收到更新"+ DateTime.Now.Ticks); |
| | | bodyView.notiyUpdateTime = DateTime.Now; |
| | | if (bodyView.updateUiThread == null) |
| | | { |
| | | bodyView.updateUiThread = new System.Threading.Thread(() => |
| | | { |
| | | while (true) |
| | | { |
| | | System.Threading.Thread.Sleep(1500); |
| | | if(bodyView == null) |
| | | { |
| | | return; |
| | | } |
| | | if (DateTime.Now.AddMilliseconds(-1500) > bodyView.notiyUpdateTime) |
| | | { |
| | | MainPage.Log("没有新数据,更新UI"); |
| | | break; |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log("有新数据,继续等待"); |
| | | } |
| | | } |
| | | |
| | | Application.RunOnMainThread((() => |
| | | { |
| | | try |
| | |
| | | bodyView.btnColorfulSwitch.IsSelected = colorfulState.curValue.ToString() == "on"; |
| | | } |
| | | } |
| | | }catch(Exception ex) |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"更新RGB 炫彩开关状态异常:{ex.Message}"); |
| | | } |
| | |
| | | { |
| | | MainPage.Log($"{bodyView.GetType().Name } UpdataStates error : {ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | bodyView.updateUiThread = null; |
| | | } |
| | | })); |
| | | |
| | | }); |
| | | bodyView.updateUiThread.IsBackground = true; |
| | | bodyView.updateUiThread.Start(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | d.Add(FunctionAttributeKey.Brightness, e.ToString()); |
| | | Control.Ins.SendWriteCommand(function, d); |
| | | } |
| | | else |
| | | { |
| | | if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds) |
| | | { |
| | | function.refreshTime = DateTime.Now; |
| | | new System.Threading.Thread(() => |
| | | { |
| | | //Control.Send(CommandType_A.write, function); |
| | | System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>(); |
| | | d.Add(FunctionAttributeKey.Brightness, e.ToString()); |
| | | Control.Ins.SendWriteCommand(function, d); |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log("skip dimmer control!!"); |
| | | } |
| | | } |
| | | //else |
| | | //{ |
| | | // if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds) |
| | | // { |
| | | // function.refreshTime = DateTime.Now; |
| | | // new System.Threading.Thread(() => |
| | | // { |
| | | // //Control.Send(CommandType_A.write, function); |
| | | // System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>(); |
| | | // d.Add(FunctionAttributeKey.Brightness, e.ToString()); |
| | | // Control.Ins.SendWriteCommand(function, d); |
| | | // }) |
| | | // { IsBackground = true }.Start(); |
| | | // } |
| | | // else |
| | | // { |
| | | // MainPage.Log("skip dimmer control!!"); |
| | | // } |
| | | //} |
| | | }; |
| | | } |
| | | } |