EDIT: It was discovered to be DirectInput, and not SlimDX
Since updating my PC to Windows 10, the PC never goes to Sleep when my application is running, and I've narrowed it down to a single call from SlimDX.
My application is a type of UI browser - think of Kodi or Steam Big Picture mode. It is designed to allow the computer to go to sleep when the interface is up, but not being used (through the normal Windows mechanism of Power Settings).
This was working just fine on Windows 7, but since upgrading to Windows 10 - and with no changes to my application - it no longer sleeps if a gamepad is plugged in (traditional gamepad, not XInput).
I've traced it down to a single call in SlimDX: Joystick.GetCurentState(). If I comment out this single line, leaving in the acquiring of the joysticks, the Poll(), as well as all the rest of my code, the computer then goes to sleep. Of course, the joystick doesn't work.
I threw together a quick pure DirectX C++ app that does the same thing, just runs, scans the joysticks, and prints changes to the state via IDirectInputDevice8::Poll() and IDirectInputDevice8::GetDeviceState(). The app works and shows joystick button presses and DPad movement, and it properly lets the computer sleep if there is no activity for the system sleep timeout time. So it appears this is entirely related to SlimDX on Windows 10.
Has anyone encountered this before? Is there any way to work around it without writing my own joystick input library to connect to my C# code?
Here's some possibly relevant info:
- I'm using the joystick with cooperative level Nonexclusive | Background (did the same in my test C++ app)
- I hacked together a quick and dirty Windows Raw Input test, that didn't parse the input but simply printed when a message was received. It shows messages when I push a button, but no Raw Input is received when the gamepads are idle.
- Calling the Windows GetLastInputInfo() function says no input is received. That function returns the system tick count of the last input event across the whole system, and it doesn't change while the gamepads are idle, but the computer still doesn't sleep.
- The only thing I got some info from was CallNtPowerInformation(SystemPowerInformation). One of the values returned from that is the number of seconds until the computer goes to sleep. When my app is running, that number does not decrease. When I comment out that single line (Joystick.GetCurrentState()), the counter then does decrease, and the computer goes to sleep when it hits 0.