32

I need to prevent the screen from automatically locking itself if the user dont interact with the device for a while.

Is it possible to request some kind of lock to keep the screen on while running my application?

jorgenfb
  • 2,215
  • 1
  • 21
  • 31

2 Answers2

48

Yes, you can do this by disabling UserIdleDetection.

Samples and more background info here.

PhoneApplicationService.UserIdleDetectionMode Property (Microsoft.Phone.Shell)

Idle Detection for Windows Phone

Mick N
  • 14,892
  • 2
  • 35
  • 41
  • Thanks Mick, works great. Sadly I dont have enough reputation points to upvote your answer. – jorgenfb Dec 02 '10 at 21:50
  • This answer is incorrect. The pages you link to specify that UserIdleDetectionMode enabled the application to continue to run once the phone has been locked, but it does not prevent the lock screen from appearing. – Richard Szalay Dec 03 '10 at 07:33
  • 4
    @Richard: Mick's answer is correct. ApplicationIdleDetectionMode allows the app to continue running when the screen is locked, while UserIdleDetectionMode disable the auto-lock on idle. – Francesco De Vittori Dec 03 '10 at 10:19
  • Thanks Mick for the correct answer. I had to read the answer 5+ times before I realized what was wrong with my code. So for the rest of you if your code still doesn't work: there are 2 similar properties to set: ApplicationIdleDetectionMode AND UserIdleDetectionMode. See Francesco's comment for more info. – Buju Mar 23 '12 at 12:31
  • both should be disabled to avoid screen to lock ? – Tim Apr 04 '13 at 09:09
  • @jorgenfb: I am upvoting on your behalf – Mubashar Apr 19 '14 at 16:59
28

I did not found example code in MSDN, so I decided to put it up here because I was also looking for an answer to this problem:

using Microsoft.Phone.Shell;

PhoneApplicationService phoneAppService = PhoneApplicationService.Current;
phoneAppService.UserIdleDetectionMode = IdleDetectionMode.Disabled;
ctacke
  • 66,480
  • 18
  • 94
  • 155
Markus Rudel
  • 1,318
  • 15
  • 30
  • 4
    You can do it in one line if your want `PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;`. – aloisdg May 10 '14 at 13:13