Search code examples
c#windows-runtimewindows-store-apps

Is it possible to prevent lock screen in Windows 10 uwp?


I'm developing an app for Windows 10 where there is a slides show, and i want to prevent the auto lock for the screen (turn off).. is it possible?


Solution

  • You could use this class to do that Windows.System.Display.DisplayRequest:

    private Windows.System.Display.DisplayRequest _displayRequest;
    
    public void ActivateDisplay()
    {
        //create the request instance if needed
        if (_displayRequest == null)
            _displayRequest = new Windows.System.Display.DisplayRequest();
    
        //make request to put in active state
        _displayRequest.RequestActive();
    }
    
    public void ReleaseDisplay()
    {
        //must be same instance, so quit if it doesn't exist
        if (_displayRequest == null)
            return;
    
        //undo the request
        _displayRequest.RequestRelease();
    }
    

    You can read more about it here: https://blogs.windows.com/buildingapps/2016/05/24/how-to-prevent-screen-locks-in-your-uwp-apps

    Please make sure again to provide what you've tried.. have you searched about it?.. Asking directly isn't a good practice as developer :).