Skip to content

System could not hook for sleep and awake event by SystemEvents.PowerModeChanged in WinUI3 Desktop App #5139

@gscheartA

Description

@gscheartA

Describe the bug
I use SystemEvents hook API in App_Launched function for computer asleep hook. Here is my code

SystemEvents.PowerModeChanged += OnPowerChange;

private void OnPowerChange(object s, PowerModeChangedEventArgs e)
{
switch ( e.Mode )
{
case PowerModes.Resume:
break;
case PowerModes.Suspend:
break;
}
}

But it does not work after I let my computer sleep and asleep.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Add the code above
  2. Sleep and wake computer , the event could not be triggered

Expected behavior
The event could be detected.

Version Info

NuGet package version:
[WinUI 3 - Project Reunion 0.5: 0.5.0]

Windows app type:
Win32

OS:
October 2020 Update (19042)

Desktop

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-ExternalNot owned by the WinUI team, not actionable in this repository.needs-triageIssue needs to be triaged by the area owners

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions