In this article we are going to see how to disable the screen locking feature while we debugging the application on the emulator or the device. When we develop our application and to test it on the emulator or the device on certain scenarios we need to disable the automatic screen lock to test the application feature. In real device we can avoid the automatic screen lock by changing the settings where as in the emulator to test it we need to manage in the code itself to make the lock screen disabled while debugging the application. [more]
To debug the application from the Visual Studio IDE we need to keep the mode to debug as the release mode will not allow to debug the code to get the progress by selecting the debug option from the Debugger type. Let us see how to debug the application with making the screen lock disabled for debugging. Open Visual Studio 2012 IDE in administrator mode and create a new Windows Phone project with a valid project name as shown in the screen below.
Clicking on OK will create the project and the solution with the list of default files and folders that are required to run the application. It will take some time to create these files based on your system configuration, so once everything is ready we can see the Visual Studio IDE with the project as shown in the screen below.
To lock the screen while debugging from the emulator we need add the below code which basically checks if the debugger is enabled and makes the IdleDetectionmode to disabled which makes the lock screen to take action to lock the screen on the debugger mode as shown in the below code which we can write on the app load event.
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
Now run the application in the emulator and we can see the application loads into the emulator and lock screen will not function as we run the application in debugging mode.