JasonWei512 / EnergyStarX

🔋 Improve your Windows 11 device's battery life. A WinUI 3 GUI for https://github.com/imbushuo/EnergyStar.
https://www.microsoft.com/store/productId/9NF7JTB3B17P
GNU General Public License v3.0
906 stars 19 forks source link

睡眠后应用会被杀掉 / App crashes when PC wakes up from sleep #11

Closed Taylorc0804 closed 1 year ago

Taylorc0804 commented 1 year ago

Description / 描述

设备YOGA 14S 2021英特尔版本,百分比复现

Reproduction steps / 复现步骤

1. 睡眠
2. 关闭睡眠后开启就发现应用被杀掉了
3.

Screenshots / 截图

No response

Windows version / Windows 版本

Windows 11 22623.875

Hardware specs / 硬件配置

yoga 14s 处理器 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz 2.42 GHz 机带 RAM 16.0 GB (15.8 GB 可用)

JasonWei512 commented 1 year ago

我这里没法复现这个问题。这个 Bug 有点头疼。

Taylorc0804 commented 1 year ago

你好,不好意思,现在才看到。我也不太清楚是S0还是S3,睡眠后需要按键盘手动唤醒,然后windows hello 识别到人脸就唤醒进入桌面了 。 我按照你说的运行了原版的 EnergyStar,睡眠后也会被杀死。erro log如下

管道的另一端上无任何进程。 at System.ConsolePal.WindowsConsoleStream.Write(ReadOnlySpan`1 ) at System.IO.StreamWriter.Flush(Boolean , Boolean ) at System.IO.StreamWriter.WriteLine(String ) at System.IO.TextWriter.SyncTextWriter.WriteLine(String ) at System.Console.WriteLine(String ) at EnergyStar.EnergyManager.HandleForegroundEvent(IntPtr hwnd) in C:\Users\USER\Code\EnergyStar\EnergyStar\EnergyManager.cs:line 142 at EnergyStar.Interop.HookManager.WindowEventCallback(IntPtr hWinEventHook, UInt32 eventType, IntPtr hwnd, Int32 idObject, Int32 idChild, UInt32 dwEventThread, UInt32 dwmsEventTime) in C:\Users\USER\Code\EnergyStar\EnergyStar\Interop\HookManager.cs:line 52

JasonWei512 commented 1 year ago

@Taylorc0804 非常感谢,我大概知道问题出在哪里了。

EnergyStar (Debug).zip 上面是 EnergyStar 的修改版。你再试一下,看看唤醒时还会不会崩溃。如果还是崩溃,那么把 error.txt 发上来。

Taylorc0804 commented 1 year ago

@JasonWei512 你好,我试了你发的版本,无论是短时间还是长时间睡眠唤醒都不会有应用被杀掉的问题了,也没有error的log,看来很快就能享受到新版本了,期待更新...

xgdgsc commented 1 year ago

x64 版偶尔出现, arm上每次都出现(matebook e go)

JasonWei512 commented 1 year ago

我上传 0.3.10 到商店了,全面推送可能还要等一会。更新之后你可以试一下睡眠还会不会崩溃。

xgdgsc commented 1 year ago

arm版更新后休眠后仍然会自动退出, 没有安装任务栏修改软件, error log是空的. 休眠后同样退出的还有slack的客户端,不知道相关不, 供参考

JasonWei512 commented 1 year ago

好像又是托盘图标的问题。 下周末修复。

image

https://github.com/HavenDV/H.NotifyIcon/issues/50

JasonWei512 commented 1 year ago

1.0.2 版本更新了。 @xgdgsc 可以试一下还会不会崩溃。

xgdgsc commented 1 year ago

好,这2天上一版也没崩溃, 不清楚为什么.

JasonWei512 commented 1 year ago

从后台崩溃数据来看应该已经在 1.0.2 中修复。

According to crash telemetry, this bug should have been fixed in 1.0.2.

xgdgsc commented 1 year ago

最近我arm64又出现稳定崩溃了,之前其他应用有的直接用开发者提供的exe就不崩溃,应用商店版的就崩溃, 你也可以考虑提供个exe的给我试试

JasonWei512 commented 1 year ago

这个应用没考虑过 exe 发布。要做 exe 版的话得改好几个地方。 你更新商店版到 1.0.3 再试一下?看后台数据崩溃率很低。

还有发一下这些信息:

我手头没有 ARM64 的 Windows 设备。所以虽然往商店提交了 ARM64 的包但是一直没测试过。

xgdgsc commented 1 year ago

就是1.0.3 huawei matebook e go 性能版 windows 22000 空的 error.log 点击“联系开发者” 直接崩溃, 没有日志

JaneValleyhasBtaken commented 1 year ago

软件是最新版 1.0.3,Windows 11 22623.1037。Surface Laptop 3 (Intel CPU) 从睡眠醒来(或者modern standby..?)应用依旧会被杀死,并且无法打开,除非重启/重装.... 然后似乎这种无法启用导致了我的电脑有很多的卡顿.... 希望这个问题能被解决,因为真的好头疼。开发者辛苦了。


Software is the latest version 1.0.3, and running with Windows 11 22623.1037 on Surface Laptop 3 (Intel CPU) Wake the laptop from sleep (or modern standby...?) and the app is still killed and won't open unless restarted/reinstalled .... Then it seems this inability to enable causes a lot of lag in my computer ....

JaneValleyhasBtaken commented 1 year ago

不知道在哪来能抓到error log 不过会不会是因为这个软件被杀死之后,白名单无法启用,但是 efficiency mode 依旧在启用。然后阻止了这个软件启动...? 因为我有遇到过,把一些软件加进 efficiency mode 之后(比如说欧路词典),会导致这个软件无法用快捷键从后台拉起。

JasonWei512 commented 1 year ago

@JaneValleyhasBtaken 在应用的“日志”页底栏,点“打开日志文件夹”按钮,应该能在文件夹里看到一个 Error.log。你看看里面有没有错误日志。 还有,你用商店里另一个绿叶星图标的 EnergyStar X 时从睡眠唤醒会崩溃吗?

我怀疑还是托盘图标的缘故。 这个应用用的是 HavenDV/H.NotifyIcon 库。 后台的崩溃统计里基本都是跟托盘图标有关。

image

JaneValleyhasBtaken commented 1 year ago

@JasonWei512 查看了一下,error log是空的,从睡眠崩溃了之后也没有任何log

JaneValleyhasBtaken commented 1 year ago

这一次从睡眠中出来都没遇到崩溃,反而是在电脑运行途中时崩溃了(指右下角托盘里的图标消失),而在此之前我重启过资源管理器。 而后,在试图重新打开ESX时,会弹出消息“已经在运行”,除此之外依旧没有托盘图标,也无法打开。 我查看了一下消息历史,发现前几次的时候也有弹过类似的通知但无法运行(只不过我开着免打扰没有注意到)。

可能从睡眠中唤醒然后崩溃是个错觉...?可能跟资源管理器有关?我也不清楚,但Error Log是一片空白。

FvNCCR228 commented 1 year ago

我这里没法复现这个问题。这个 Bug 有点头疼。

  • 你的电脑待机是 S0 的 Modern Standby / Connected Standby(可以像手机一样立即唤醒),还是传统的 S3 睡眠(唤醒比较慢,要几秒到十几秒)?
  • 这个是原版的 EnergyStar:EnergytStar.zip 下载后把它解压,双击运行之后应该可以看到一个黑色的控制台窗口,上面会显示一些信息。 然后把你的电脑睡眠,然后再唤醒。 这个时候,这个原版的 EnergyStar 有没有崩溃?黑色的控制台窗口还在吗? 在同一个文件夹下有没有看到一个 error.txt?有的话发上来。

联想的笔记本一般应该都是s0模式

JasonWei512 commented 1 year ago

这一次从睡眠中出来都没遇到崩溃,反而是在电脑运行途中时崩溃了(指右下角托盘里的图标消失),而在此之前我重启过资源管理器。 而后,在试图重新打开ESX时,会弹出消息“已经在运行”,除此之外依旧没有托盘图标,也无法打开。 我查看了一下消息历史,发现前几次的时候也有弹过类似的通知但无法运行(只不过我开着免打扰没有注意到)。

可能从睡眠中唤醒然后崩溃是个错觉...?可能跟资源管理器有关?我也不清楚,但Error Log是一片空白。

这个也是一个 HavenDV/H.NotifyIcon 的问题。重启了资源管理器后托盘图标会消失,但是实际上 能源之星X 还是在运行(可以从任务管理器里杀掉)。 等我有空看看有没有解决办法。

leftxxxx commented 1 year ago

开发者好,我的设备也是YOGA 14S 2021英特尔版本,使用联想的智能感应功能进入现代待机模式后,超过3分钟左右,重新唤醒,该应用就会自动退出。所有微软商店下载的应用都有这个问题。之前win10没有这个问题,升级win11之后出现的,我这里百分百复现。 以下是错误日志: 2023-01-07 17:47:44.5634|ERROR|EnergyStarX.App|Unhandled and unrecoverable exception|System.InvalidOperationException: TryCreate failed. at H.NotifyIcon.Core.TrayIcon.Create() in /_/src/libs/H.NotifyIcon/Core/TrayIcon.cs:line 226 at H.NotifyIcon.Core.TrayIconWithContextMenu.b150() in //src/libs/H.NotifyIcon/PopupMenus/TrayIconWithContextMenu.cs:line 56 2023-01-07 17:53:53.1214|ERROR|EnergyStarX.App|Unhandled and unrecoverable exception|System.InvalidOperationException: TryCreate failed. at H.NotifyIcon.Core.TrayIcon.Create() in /_/src/libs/H.NotifyIcon/Core/TrayIcon.cs:line 226 at H.NotifyIcon.Core.TrayIconWithContextMenu.b__150() in //src/libs/H.NotifyIcon/PopupMenus/TrayIconWithContextMenu.cs:line 56 2023-01-07 17:54:43.3723|ERROR|EnergyStarX.App|Unhandled and unrecoverable exception|System.InvalidOperationException: TryCreate failed. at H.NotifyIcon.Core.TrayIcon.Create() in /_/src/libs/H.NotifyIcon/Core/TrayIcon.cs:line 226 at H.NotifyIcon.Core.TrayIconWithContextMenu.b150() in //src/libs/H.NotifyIcon/PopupMenus/TrayIconWithContextMenu.cs:line 56 2023-01-07 17:56:01.5053|ERROR|EnergyStarX.App|Unhandled and unrecoverable exception|System.InvalidOperationException: TryCreate failed. at H.NotifyIcon.Core.TrayIcon.Create() in /_/src/libs/H.NotifyIcon/Core/TrayIcon.cs:line 226 at H.NotifyIcon.Core.TrayIconWithContextMenu.b__150() in //src/libs/H.NotifyIcon/PopupMenus/TrayIconWithContextMenu.cs:line 56

xgdgsc commented 1 year ago

更新22h2后没再崩溃了

xgdgsc commented 1 year ago

又出现了,好像用电池恢复的时候会出现,插电恢复不会

leftxxxx commented 1 year ago

又出现了,好像用电池恢复的时候会出现,插电恢复不会

现代待机模式的锅

JasonWei512 commented 1 year ago

有点没辙了 😂 没法复现,也没有 ARM 设备 等我有空再看一下后台的崩溃数据

JasonWei512 commented 1 year ago

@xgdgsc 解压这个压缩包,然后运行其中的 exe。

SystemProductName.zip

你应该能看到类似于下面这样的信息:

Your SystemProductName is: {设备名}

Press any key to exit ...

麻烦把这个 {设备名} 发上来。

xgdgsc commented 1 year ago

Your SystemProductName is: GK-W7X. 谢谢

JasonWei512 commented 1 year ago

@xgdgsc 后台还是查不到你的设备的崩溃记录 头疼

xgdgsc commented 1 year ago

现在log不是空的了


2023-03-05 09:17:18.9847|ERROR|EnergyStarX.App|Unhandled and unrecoverable exception|System.InvalidOperationException: TryCreate failed.
   at H.NotifyIcon.Core.TrayIcon.Create() in /_/src/libs/H.NotifyIcon/Core/TrayIcon.cs:line 226
   at H.NotifyIcon.Core.TrayIconWithContextMenu.<Create>b__15_0() in /_/src/libs/H.NotifyIcon/PopupMenus/TrayIconWithContextMenu.cs:line 56
JasonWei512 commented 1 year ago

另外一个遇到睡眠崩溃问题的用户的错误日志:

2023-03-05 16:13:59.8439|ERROR|EnergyStarX.App|Unhandled and unrecoverable exception|System.InvalidOperationException: TryCreate failed.
   at H.NotifyIcon.Core.TrayIcon.Create() in /_/src/libs/H.NotifyIcon/Core/TrayIcon.cs:line 226 
   at H.NotifyIcon.Core.TrayIconWithContextMenu.<Create>b__15_0() in /_/src/libs/H.NotifyIcon/PopupMenus/TrayIconWithContextMenu.cs:line 56

软硬件信息:

Windows: 10.0.22621.0 
Device: Surface Pro 8 
CPU: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz 
RAM: 16384 MB 
GPU: Intel(R) Iris(R) Xe Graphics 
Battery: Yes 

关于这个 TryCreate failed

这个 InvalidOperationException("TryCreate failed.") 是后台崩溃和错误数据里占比最高的一项。似乎遇到睡眠崩溃的用户都遇到过这个异常?

但是我看了 H.NotifyIcon 的代码,好像只有在一开始初始化托盘图标的时候会调用 bool TrayIcon.TryCreate()。应用启动完成后应该就不会调用这个方法了。所以不清楚睡眠崩溃和它有没有关。

xgdgsc commented 1 year ago

你试过作者说的这个思路吗 https://github.com/HavenDV/H.NotifyIcon/issues/50#issuecomment-1302314891

JasonWei512 commented 1 year ago

试过。1.0.2 里给更新托盘图标的 Icon 和 ToolTip 的两行代码套了个 try catch 之后,后台崩溃记录少了很多(但不是上上楼里说的那个异常)。 时间节点在 https://github.com/JasonWei512/EnergyStarX/issues/11#issuecomment-1336323203https://github.com/JasonWei512/EnergyStarX/issues/11#issuecomment-1348378742 之间。那个 issue 的楼主也说 "It's easy enough for my software to catch this exception"。 库作者说的这个 SystemEvents.PowerModeChanged += OnPowerChange; 我试过好像不能 100% 保证在 Modern Standby 机型上触发。

AsukaXX commented 1 year ago

上上上楼那个Surface pro 8就是我,我电脑有个很奇怪的问题,基本从微软商店下的应用后台都挂不住,手机连接那个应用,从睡眠中唤醒也会被杀掉,但是像PowerToys这种非微软商店应用就没这个问题,我怀疑是系统的问题

xgdgsc commented 1 year ago

https://answers.microsoft.com/en-us/windows/forum/all/win-11-microsoft-stores-apps-close-on-while-on/7afc907d-0ba8-4334-96ab-c5b9eec5b88a

JasonWei512 commented 1 year ago

看来商店应用睡眠唤醒后崩溃是个 Windows 的问题。 Windows Terminal 的人说微软内部注意到了这个问题,并获得了很多关注:https://github.com/microsoft/terminal/issues/12513#issuecomment-1411236634

在微软修复这个问题之前,目前综合看下来有两种可能的临时解决方法:

  1. 把“手机连接”这个 APP 删了,或者在任务管理器的启动页里禁止它开机启动;

  2. 重新注册商店应用的清单(我没试过,谨慎使用)。在管理员权限 PowerShell 中运行:

    Get-AppxPackage -AllUsers | Foreach { Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml" }

    可能需要重启电脑。


For English users:

For some users, your Microsoft Store apps (including this app) may crash when your laptop is waking up from Modern Standby sleep mode.

This is an issue of Windows 11 itself. Microsoft is tracking this issue internally and it has gotten a lot of attention: https://github.com/microsoft/terminal/issues/12513#issuecomment-1411236634

Before Microsoft fixes this, there are some possible workarounds:

Related discussion:

AsukaXX commented 1 year ago

我把手机链接里的即时热点关了,目前还没有杀后台的情况

leftxxxx commented 1 year ago

Windows Terminal 的人说微软内部注意到了这个问题,并获得了很多关注:microsoft/terminal#12513 (comment)

在微软修复这个问题之前,目前综合看下来有两种可能的临时解决方法:

  1. 把“手机连接”这个 APP 删了,或者在任务管理器的启动页里禁止它开机启动;
  2. 重新注册商店应用的清单(我没试过,谨慎使用)。在管理员权限 PowerShell 中运行:

    Get-AppxPackage -AllUsers | Foreach { Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml" }

    可能需要重启电脑。

第二方法我试了,在重置的时候显示很多应用无法重置,因为被占用,等代码跑完以后,我重启了电脑,还是会闪退。

leftxxxx commented 1 year ago

同样是微软商店下载的auto dark mode 这个软件就不会崩溃,不知道为啥。

myfix16 commented 1 year ago

同样是微软商店下载的auto dark mode 这个软件就不会崩溃,不知道为啥。

Auto Dark Mode只是在store上架,它的部署方式应该不是提交到store的.msixupload,而是传统exe。所以应该不能用这个类比。

image
leftxxxx commented 1 year ago

同样是微软商店下载的auto dark mode 这个软件就不会崩溃,不知道为啥。

Auto Dark Mode只是在store上架,它的部署方式应该不是提交到store的.msixupload,而是传统exe。所以应该不能用这个类比。 image

学到了

myfix16 commented 1 year ago

看起来微软修复了这个bug。根据这篇反馈中心帖子这个补丁会包含对应的patch。

English version: Microsoft has fixed this issue. As mentioned in this feedback hub post

Thanks for taking the time to report this. We've made a fix for this with Build 22621.1485 (https://support.microsoft.com/topic/march-28-2023-kb5023778-os-build-22621-1485-preview-d490bb51-492e-410c-871f-50ad01b0f765) which should address this for apps like Windows Terminal and Notepad.

We've made another fix to help with this in the latest Canary Channel builds. If you're continuing to experience issues, please don't hesitate to file a new piece of feedback to let us know (if possible citing the app that you're seeing it with)

leftxxxx commented 1 year ago

看起来微软修复了这个bug。根据这篇反馈中心帖子这个补丁会包含对应的patch。

English version: Microsoft has fixed this issue. As mentioned in this feedback hub post

Thanks for taking the time to report this. We've made a fix for this with Build 22621.1485 (https://support.microsoft.com/topic/march-28-2023-kb5023778-os-build-22621-1485-preview-d490bb51-492e-410c-871f-50ad01b0f765) which should address this for apps like Windows Terminal and Notepad. We've made another fix to help with this in the latest Canary Channel builds. If you're continuing to experience issues, please don't hesitate to file a new piece of feedback to let us know (if possible citing the app that you're seeing it with)

我测试了几天,确实,进入现代待机模式后,微软商店的应用不会自动关闭了。

JasonWei512 commented 1 year ago

微软已经修复了这个问题,所以我把这个 issue 关了。 Since Microsoft has fixed this bug, I will close this issue.