I'm capturing screen using CopyFromScreen. When someone locks PC, then it's starting to throw exception System.ComponentModel.Win32Exception (0x80004005): The handle is invalid
. To avoid it, I'm checking current session state using SystemState.SessionSwitch. It's a good solution, but when I'm capturing screen with speed 30 screenshots per second, then it is fast enough to fire this exception 1/2 times before I switch flag state in SessionSwitch
event. Is there any way to check current session state in catch
block or to check if handle is valid before I invoke CopyFromScreen
?
User contributions licensed under CC BY-SA 3.0