Capture Vista/XP Sleep Event (ACPI?)

Aug 30 2008 3:59 AM
Hello,

I have a USB device, that I need to send 1 packet to before the computers go to sleep. I tried capturing the Microsoft.Win32.SystemEvents.PowerModeChanged event and if e.Mode is Suspend, then I do my code I need. Problem is, it doesnt work. It sends to 1 device, and then the system suspends. If I have to 2 devices, it sends to 1 not both. If I run the exact same function while the computer is running stable, it works perfect.

So my thinking is the event is not being fired when the system gets the "suspend" message, but a while after, and then there is not enough time to do both. I have it running on a seperate thread too to try and speed it up, but it isnt.

Is there an API call that I can get that works better? Or is there a better way? I need to send 1 byte[] to each device before suspend. Ideally, I would like to capture the suspend call, cancel it, do my thing, and re-enable it.

Or even put a flag up somehow. Like those programs that "computer cant go to sleep program is preventing it" type flag, until communication is done, lower flag, and do the power state it tried to do before...

Thanks in advance