I'm writing a C# app (specifically for laptops) and I want to be aware of the state of the lid, i.e. when is it open and when is it closed.
I've already used pInvoke along with Microsoft's RegisterPowerSettingNotification function with the help of this SO answer.
So, with the above I know when the lid is being closed or opened and know its state, BUT I want to get the state of the lid before anything else continues. I've noticed that even if there is no change to the lid, the callback function is called and I can check its parameter to know the lid's state, but this not good for me since it is an event and I can't simply wait for it to occur (maybe there's another way to work around this?).
I've also tried PowerEnumerate function but couldn't get something from it (maybe there is something I don't know there that could help)
EDIT 1: I can't wait or delay the app, and there are 2 issues that require me to get the state without a CB, the first is that a lid can be closed while the laptop is connected to a monitor thus allowing the user to use the laptop. If the user starts the app in this situation it should not start. The second reason is that I want the app to be user friendly and notify what happens when it starts or stops, and if I get the cb in the wrong time it might be ignored, due to the app's inner logic, and then will have to wait until the next time I get a cb, I'd at all.
So, (no pun intended) Is there a way to get this information right away?
EDIT 2: It seems from comments that it's not clear what I need. I need a way to query to state of the lid. i.e. - call some API or something and that the return value is the state. thanks!
Keywords: GUID_LIDSWITCH_STATE_CHANGE , WM_POWERBROADCAST, Power Setting