[RT.Core]

新增当RT运行时,阻止系统自动进入休眠或关闭屏幕的功能。
This commit is contained in:
SL 2024-01-17 09:49:18 +08:00
parent 3730cfabc7
commit 308802c75a
4 changed files with 42 additions and 4 deletions

View File

@ -116,7 +116,6 @@ namespace Aitex.Core.RT.Device
{
lock (_lockerDevice)
{
var rnd = new Random();
foreach (var value in _nameDevice.Values)
{
try

View File

@ -823,6 +823,7 @@
<Compile Include="MECF\Framework\Common\Utilities\Sha256.cs" />
<Compile Include="MECF\Framework\Common\Utilities\StringGZip.cs" />
<Compile Include="MECF\Framework\Common\Utilities\SystemInfoHelper.cs" />
<Compile Include="MECF\Framework\Common\Utilities\WIN32APIsWrapper.cs" />
<Compile Include="MECF\Framework\RT\Core\FAServices\Gem300Service.cs" />
<Compile Include="MECF\Framework\RT\Core\FAServices\GemService.cs" />
<Compile Include="MECF\Framework\RT\Core\FAServices\IGemCallback.cs" />

View File

@ -0,0 +1,33 @@
using System;
using System.Runtime.InteropServices;
namespace MECF.Framework.Common.Utilities
{
public static class WIN32APIsWrapper
{
[FlagsAttribute]
public enum EXECUTION_STATE : uint
{
ES_AWAYMODE_REQUIRED = 0x00000040,
ES_CONTINUOUS = 0x80000000,
ES_DISPLAY_REQUIRED = 0x00000002,
ES_SYSTEM_REQUIRED = 0x00000001
// Legacy flag, should not be used.
// ES_USER_PRESENT = 0x00000004
}
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
public static void PreventSleep(bool isDisable = false)
{
if (isDisable)
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
else
// Prevent Idle-to-Sleep (monitor not affected) (see note above)
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_AWAYMODE_REQUIRED |
EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_SYSTEM_REQUIRED);
}
}
}

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
@ -13,8 +12,8 @@ using Aitex.Core.RT.Log;
using Aitex.Core.Util;
using MECF.Framework.Common.CommonData;
using MECF.Framework.Common.NotifyTrayIcons;
using MECF.Framework.Common.Utilities;
using MECF.Framework.RT.Core.Backend;
using MenuItem = System.Windows.Controls.MenuItem;
namespace MECF.Framework.RT.Core.Applications
{
@ -79,7 +78,10 @@ namespace MECF.Framework.RT.Core.Applications
{
MainView.Show();
}
// 禁止自动休眠或关闭屏幕
WIN32APIsWrapper.PreventSleep();
// 获取RT依赖的Dll列表
var assem = AppDomain.CurrentDomain.GetAssemblies();
ReferencedAssemblies =
@ -247,6 +249,9 @@ namespace MECF.Framework.RT.Core.Applications
MainView.Close();
}
// 恢复自动休眠或关闭屏幕
WIN32APIsWrapper.PreventSleep(true);
System.Windows.Application.Current.Shutdown(0);
Environment.Exit(0);