-
Hi Is it possible to have an MSIX packaged WindowsAppSDK application to do some task either when the PC goes into sleep/hibernate mode or maybe when it returns/resume from sleep/hibernate mode. Something similar to .Net code like Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(OnSessionSwitch);
private void OnSessionSwitch(object sender, SessionSwitchEventArgs e)
{
// do the magic
} I need it to run some simple "killtask" command either when the pc goes into sleep/hibernate mode or returns. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
You can intercept WM_POWERBROADCAST, with SetWindowSubclass |
Beta Was this translation helpful? Give feedback.
-
For example :
|
Beta Was this translation helpful? Give feedback.
-
On my PC, I get 0x0004 then 0x0007, 0x0012 Maybe you can register notifications, for example with PowerRegisterSuspendResumeNotification A quick test :
Callback :
Declarations :
|
Beta Was this translation helpful? Give feedback.
-
Hmmm... copied the above code extract into an existing WinUI3 app and I just get process exited code 0 during sleep/resume. Had success with microsoft/microsoft-ui-xaml#5139 |
Beta Was this translation helpful? Give feedback.
On my PC, I get 0x0004 then 0x0007, 0x0012
Maybe you can register notifications, for example with PowerRegisterSuspendResumeNotification
A quick test :