App receiving PM SUSPEND event notification after the system resumes.

Hello,
I have an app that opens up a handle to a device through CreateFile.

The app needs to close the handle for the device while system goes to S3/S4.
and reopen the handle on resume.

So I thought I could handle the message WM_POWERBROADCAST with wParam
PBT_APMRESUMESUSPEND.
To my surprise, I am getting both suspend notification & resume notification
AFTER the system resume!!!

What could be wrong? what is the right thing to do?

-Maddy

>The app needs to close the handle for the device while system goes to S3/S4. and reopen the handle

on resume.

Why? Power management is hidden from apps usually.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

“Madhusudan Narayan” wrote in message
news:xxxxx@ntdev…
> Hello,
> I have an app that opens up a handle to a device through CreateFile.
>
> The app needs to close the handle for the device while system goes to
> S3/S4.
> and reopen the handle on resume.
>
> So I thought I could handle the message WM_POWERBROADCAST with wParam
> PBT_APMRESUMESUSPEND.
> To my surprise, I am getting both suspend notification & resume
> notification
> AFTER the system resume!!!
>
> What could be wrong? what is the right thing to do?
>
> -Maddy

There is no guarantee that usermode app will receive suspend notification
before the suspend occurs.
So nothing is wrong, this is correct behaviour.
Also, you’ve seen that suspend & resume was successful, even though you have
not closed the handle.
Perhaps there was no reason to close the handle at all. Instead, the app can
register
for PnP notifications, to detect removal request. Then, it must close the
handle.
–pa