tags:

views:

120

answers:

2

I'm writing a desktop application and would like to know if there are any events that get fired on AC power status changed.

+1  A: 

I don't believe there's anything in the BCL that raises an event on such a change. Do you really need one anyway, given the infrequency of such status updates?

I would simply poll the SystemInformation.PowerStatus property at regular intervals (i.e. some number of seconds). You can then raise an event based on this, if you wish.

Noldorin
+2  A: 

There is an event, which Windows sends to a window, when power setting changes. It's WM_POWERBROADCAST and its wParam PBT_POWERSETTINGCHANGE. If needed, you can then after receiving this event pool SystemInformation.PowerStatus as Noldorin suggested.

mnn