更新自动退出相关代码
This commit is contained in:
parent
ed6c98aa3b
commit
33cbdb530e
|
|
@ -37,7 +37,7 @@
|
|||
<!-- 按处方还药或者按取药记录还药 1:处方(ReturnDrugWindow2)2:药品(ReturnDrugWindow)-->
|
||||
<add key="returnDrugMode" value="2" />
|
||||
<!-- 自动退出时间,单位秒,为0时不自动退出 -->
|
||||
<add key="autoExit" value="0"/>
|
||||
<add key="autoExit" value="10"/>
|
||||
|
||||
<!-- 无操作退出录像时间,单位秒,为0时不退出录像 -->
|
||||
<add key="stopRecord" value="0"/>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,13 @@
|
|||
using log4net;
|
||||
using DM_Weight.Common;
|
||||
using DM_Weight.Models;
|
||||
using DM_Weight.msg;
|
||||
using DM_Weight.Port;
|
||||
using DM_Weight.util;
|
||||
using DM_Weight.Views;
|
||||
using log4net;
|
||||
using log4net.Repository.Hierarchy;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Prism.Commands;
|
||||
using Prism.Events;
|
||||
using Prism.Mvvm;
|
||||
|
|
@ -10,22 +19,14 @@ using System.Collections.Generic;
|
|||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using DM_Weight.Models;
|
||||
using DM_Weight.Port;
|
||||
using DM_Weight.util;
|
||||
using DM_Weight.Views;
|
||||
using System.Timers;
|
||||
using Unity;
|
||||
using System.Windows.Threading;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using DM_Weight.msg;
|
||||
using System.Threading;
|
||||
using DM_Weight.Common;
|
||||
using System.Windows.Media;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using System.Windows.Threading;
|
||||
using Unity;
|
||||
|
||||
namespace DM_Weight.ViewModels
|
||||
{
|
||||
|
|
@ -571,8 +572,9 @@ namespace DM_Weight.ViewModels
|
|||
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
|
||||
if (autoExit > 0)
|
||||
{
|
||||
logger.Info("启动自动退出检测");
|
||||
//int interval = autoExit * 1000;
|
||||
new PromiseUtil<int>().taskAsyncLoop(1000, 0, async (options, next, stop) =>
|
||||
new PromiseUtil<int>().taskAsyncLoop(10, 0, async (options, next, stop) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -590,8 +592,10 @@ namespace DM_Weight.ViewModels
|
|||
stop();
|
||||
System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
|
||||
{
|
||||
|
||||
DialogHost.Close("RootDialog");
|
||||
if (DialogHost.IsDialogOpen("RootDialog"))
|
||||
{
|
||||
DialogHost.Close("RootDialog");
|
||||
}
|
||||
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||
}));
|
||||
//});
|
||||
|
|
@ -601,10 +605,12 @@ namespace DM_Weight.ViewModels
|
|||
{
|
||||
if (Operator == null)
|
||||
{
|
||||
logger.Info("自动退出检测已停止");
|
||||
stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Info($"停止操作时间{_portUtil.dateTime},自动退出时间{autoExit},运算结果{(DateTime.Now - _portUtil.dateTime).TotalSeconds},用户上次使用系统到现在的时间间隔{CheckComputerFreeState.GetLastInputTime()}");
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,9 +44,23 @@ namespace DM_Weight.util
|
|||
}
|
||||
else
|
||||
{
|
||||
var count = (Environment.TickCount & Int32.MaxValue) - (long)vLastInputInfo.dwTime;
|
||||
var icount = count / 1000;
|
||||
return icount;
|
||||
//var count = (Environment.TickCount & Int32.MaxValue) - (long)vLastInputInfo.dwTime;
|
||||
//var icount = count / 1000;
|
||||
//return icount;
|
||||
|
||||
// 使用 64 位 TickCount 避免回绕问题
|
||||
long currentTick = Environment.TickCount64;
|
||||
long lastInputTick = vLastInputInfo.dwTime;
|
||||
|
||||
// 处理可能的回绕(虽然使用 64 位后极不可能发生)
|
||||
if (currentTick < lastInputTick)
|
||||
{
|
||||
// 发生了回绕,调整计算
|
||||
lastInputTick -= uint.MaxValue + 1L;
|
||||
}
|
||||
|
||||
long elapsedMilliseconds = currentTick - lastInputTick;
|
||||
return Math.Max(0, elapsedMilliseconds / 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue