New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SystemEvents.PowerModeChanged not fireing if computer is put to sleep over start menu #78162
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-microsoft-win32 Issue DetailsThis issue has been moved from a ticket on Developer Community. [severity:It bothers me. A fix would be nice]
It should tell weather the system has been suspended or not. However this is only the case if the system goes to sleep by itself. This can be set in the system settings. If I put the system to sleep manually. The PowerModeChanged event is not fired at all. Is there another Function to catch that or is this an error in windows? I do not remember it being the case with windows 10. Original CommentsFeedback Bot on 10/28/2022, 04:40 AM:(private comment, text removed) Original Solutions(no solutions)
|
Mislav Boras (original submitter in VS Feedback) hopefully you see this message: what .NET version did you use to test this? |
I wrote a small test console app and was able to repro with .NET 6 and .NET 8 in Windows 11:
Here's the app: using Microsoft.Win32;
using System;
namespace ConsoleApp;
public class Program
{
public static void Main()
{
SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(OnPowerModeChange);
Console.WriteLine("Running...");
Console.ReadLine();
}
private static void OnPowerModeChange(object s, PowerModeChangedEventArgs e)
{
Log("OnPowerModeChange");
try
{
Log(e.Mode.ToString());
}
catch (Exception ex)
{
Log($"Exception: {ex.Message}\n" + $"Stacktrace:\n{ex.StackTrace}\n\n");
}
}
private static void Log(string content) => Console.WriteLine($"{DateTime.Now} : {content}");
} Our unit tests pass by manually registering the Windows messages and detecting them in these APIs: runtime/src/libraries/Microsoft.Win32.SystemEvents/tests/SystemEvents.PowerMode.cs Lines 17 to 49 in d4d0812
So this looks a lot like a Windows 11 issue. |
This issue has been moved from a ticket on Developer Community.
[severity:It bothers me. A fix would be nice]
I am using the following code in my application:
It should tell weather the system has been suspended or not. However this is only the case if the system goes to sleep by itself. This can be set in the system settings.
If I put the system to sleep manually. The PowerModeChanged event is not fired at all.
Is there another Function to catch that or is this an error in windows?
I do not remember it being the case with windows 10.
It is definitely a Problem on Windows 11!
Original Comments
Feedback Bot on 10/28/2022, 04:40 AM:
(private comment, text removed)
Original Solutions
(no solutions)
The text was updated successfully, but these errors were encountered: