dotnet / dotnet/runtime

SystemEvents.PowerModeChanged is not raised on suspend/resume on Surface Pro

Open
#123,773 3 comments 0 reactions 0 assignees View on GitHub
area-Microsoft.Win32 bug help wanted
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

When Surface Pro sleeps, the [SystemEvents.PowerModeChanged](https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.systemevents.powermodechanged) event is not raised

### Reproduction Steps

`SystemEvents.PowerModeChanged += (s, e) => Debug.WriteLine(e.Mode);`

### Expected behavior

Should print `Suspend` on Sleep

### Actual behavior

Prints 'Suspend' on Desktop
No output on Surface Pro

### Regression?

_No response_

### Known Workarounds

Use `PowerRegisterSuspendResumeNotification`

### Configuration

dotnet SDK 10.0.102
Windows 11 (10.0.26200)
x64

### Other information

WM_POWERBROADCAST doesn't work for laptops
https://learn.microsoft.com/en-us/windows/win32/power/wm-powerbroadcast

PowerRegisterSuspendResumeNotification is available on Windows 8+ which works as expected:
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registersuspendresumenotification

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.