From 24b5d6257b976cc42412dc314d0deceea77b53dd Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Fri, 27 Dec 2024 18:43:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E7=8A=B6=E6=80=81=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E9=97=B4=E9=9A=94=E8=AE=BE=E7=BD=AE100ms=20homeWindowViewModel?= =?UTF-8?q?=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=E6=B7=BB=E5=8A=A0=20=20=5F?= =?UTF-8?q?socketHelper.dateTime=3DDateTime.Now;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckOrderNewWindowViewModel.cs | 8 +- DM_Weight/ViewModels/HomeWindowViewModel.cs | 98 ++++++++++--------- .../ViewModels/OpenBoxNewWindowViewModel.cs | 8 +- 3 files changed, 62 insertions(+), 52 deletions(-) diff --git a/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs index 5e914a6..ea9e0e9 100644 --- a/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs @@ -877,10 +877,10 @@ namespace DM_Weight.ViewModels return; } _socketHelper.OpenStatus = true; - Thread.Sleep(200); - int i = 40; + Thread.Sleep(100); + int i = 80; int iException = 0; - new PromiseUtil().taskAsyncLoop(200, 0, async (options, next, stop) => + new PromiseUtil().taskAsyncLoop(100, 0, async (options, next, stop) => { _socketHelper.IsMultiThread = true; @@ -900,7 +900,7 @@ namespace DM_Weight.ViewModels if (i == 0) { ModbusHelper.SpeakAsync("请及时关闭药箱"); - i = 40; + i = 80; } next(); } diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs index 3785cd6..0450837 100644 --- a/DM_Weight/ViewModels/HomeWindowViewModel.cs +++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs @@ -376,6 +376,7 @@ namespace DM_Weight.ViewModels _container = container; this._eventAggregator = eventAggregator; _socketHelper = socketHelper; + _socketHelper.dateTime=DateTime.Now; //timerNew = new DispatcherTimer(); //int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0"); //if (autoExit > 0) @@ -411,49 +412,7 @@ namespace DM_Weight.ViewModels // }; // timerNew.Start(); //} - int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0"); - if (autoExit > 0) - { - int interval= autoExit * 1000; - new PromiseUtil().taskAsyncLoop(interval, 0, async (options, next, stop) => - { - try - { - if (!_socketHelper.OpenStatus) - { - // 无人操作鼠标键盘 - if ((DateTime.Now - _socketHelper.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit) - { - logger.Info($"设备内无人操作,用户【{Operator?.Nickname}】自动退出登录"); - Operator = null; - Reviewer = null; - //Application.Current.Dispatcher.Invoke(() => - //{ - System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => - { - _regionManager.RequestNavigate("MainRegion", "LoginWindow"); - })); - //}); - stop(); - //timer.Dispose(); - } - else - { - next(); - } - } - else - { - _socketHelper.dateTime = DateTime.Now; - next(); - } - } - catch (Exception ex) - { - logger.Info($"自动退出异常:{ex.Message}"); - } - }); - } + } public DelegateCommand OpenFingerDialog @@ -678,7 +637,7 @@ namespace DM_Weight.ViewModels // //WDTimer.AutoReset = true; // //WDTimer.Enabled = true; //} - + #endregion //if (stopRecord > 0) //{ @@ -699,6 +658,57 @@ namespace DM_Weight.ViewModels ////获取录像机的时间 //_chkFunction.HIK_DVR_TIME(); //_chkFunction.HIKStartDVRRecord(); + + int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0"); + if (autoExit > 0) + { + //int interval = autoExit * 1000; + new PromiseUtil().taskAsyncLoop(1000, 0, async (options, next, stop) => + { + try + { + if (!_socketHelper.OpenStatus) + { + // 无人操作鼠标键盘 + if ((DateTime.Now - _socketHelper.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit) + { + logger.Info($"设备内无人操作,用户【{Operator?.Nickname}】自动退出登录.autoExit:{autoExit};socketTime:{_socketHelper.dateTime};totalSeconds:{(DateTime.Now - _socketHelper.dateTime).TotalSeconds}{_socketHelper.dateTime};LastInputTime:{CheckComputerFreeState.GetLastInputTime()}"); + Operator = null; + Reviewer = null; + //Application.Current.Dispatcher.Invoke(() => + //{ + stop(); + System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => + { + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + })); + //}); + //timer.Dispose(); + } + else + { + if (Operator == null) + { + stop(); + } + else + { + next(); + } + } + } + else + { + _socketHelper.dateTime = DateTime.Now; + next(); + } + } + catch (Exception ex) + { + logger.Info($"自动退出异常:{ex.Message}"); + } + }); + } } //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 diff --git a/DM_Weight/ViewModels/OpenBoxNewWindowViewModel.cs b/DM_Weight/ViewModels/OpenBoxNewWindowViewModel.cs index 09c7188..82606fd 100644 --- a/DM_Weight/ViewModels/OpenBoxNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/OpenBoxNewWindowViewModel.cs @@ -709,10 +709,10 @@ namespace DM_Weight.ViewModels // stop(); // } //}); - Thread.Sleep(200); - int i = 40; + Thread.Sleep(100); + int i = 80; int iException = 0; - new PromiseUtil().taskAsyncLoop(200, 0, async (options, next, stop) => + new PromiseUtil().taskAsyncLoop(100, 0, async (options, next, stop) => { _socketHelper.IsMultiThread = true; try @@ -732,7 +732,7 @@ namespace DM_Weight.ViewModels if (i == 0) { ModbusHelper.SpeakAsync("请及时关闭药箱"); - i = 40; + i = 80; } next(); }