The PowerModeChanged event is not firing on the x64 platform

  .net, 64-bit, c++, windows

I am using Windows 10 21H1 (Build 19043.1237) with Visual Studio 2019 installed (16.11.4).

In a sample Windows forms application (set .net 4.7.2 as a target framework) an event handler for the PowerModeChanged event is added in the following way (in the form’s Load event):

private void Form1_Load(object sender, EventArgs e)
{
   Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
}

private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
   Debug.WriteLine(e.Mode);

   if (e.Mode == PowerModes.Suspend)
   {
      Debug.WriteLine("SystemEvents_PowerModeChanged - PowerModes.Suspend");
   }

   if (e.Mode == PowerModes.Resume)
   {
      Debug.WriteLine("SystemEvents_PowerModeChanged - PowerModes.Resume");
   }

   if (e.Mode == PowerModes.StatusChange)
   {
      Debug.WriteLine("SystemEvents_PowerModeChanged - PowerModes.StatusChange");
   }
}

The goal is to handle cases when a computer goes into the sleep mode and wakes up. But the event is not working on the x64 OS, at the same time on x86 platform everything works fine.

Source: Windows Questions

LEAVE A COMMENT