Ryan Bowden
Ryan Bowden

Reputation: 171

Stopping Screen Timingout - windows phone 8.1

I am Creating a Windows Phone 8.1 that display the time, Quite basic but one thing i don't want it to do is allow the phone to look. Now sadly ApplicationIdleDetectionMode does not working anymore unless you do windows phone 8.1 Silverlight application. So i have used.

var displayRequest = new Windows.System.Display.DisplayRequest();
displayRequest.RequestActive(); 

now this works on its own and stops the phone going into the lock screen.

But my application does not work it goes it times out.

public MainPage()
    {
        var displayRequest = new Windows.System.Display.DisplayRequest();
        displayRequest.RequestActive(); 

        this.InitializeComponent();

        this.NavigationCacheMode = NavigationCacheMode.Required;



        this.NavigationCacheMode = NavigationCacheMode.Required;
        DateTime datetime = DateTime.Now;
        string time = String.Format("{0:T}", datetime);
        timeTXTblock.Text = time;

        DispatcherTimer dt = new DispatcherTimer();
        dt.Interval = TimeSpan.FromMilliseconds(1000);

        dt.Tick += (s, e) => { updateTime(); };

        dt.Start();
    }

    public void updateTime()
    {
        DateTime datetime = DateTime.Now;
        string time = String.Format("{0:T}", datetime);
        timeTXTblock.Text = time;
        return;
    }

I feel it might have to do with the tick on why it might be causing it to fail. Any idea why this might be and any solution?

Upvotes: 1

Views: 1414

Answers (2)

Mark
Mark

Reputation: 84

Your DisplayRequest is going out of scope as it is only active in the constructor. Define it within the class:

DisplayRequest displayRequest;

public MainPage()
    {
        displayRequest = new Windows.System.Display.DisplayRequest();
        displayRequest.RequestActive(); 
...

Upvotes: 4

I've tested your code and it worked. Then screen did not locked. DisplayRequest ( http://msdn.microsoft.com/en-us/library/windows.system.display.displayrequest.aspx ) is the way to go for non-Silverlight apps for Windows Phone.

Upvotes: 0

Related Questions