0

I am working on a timer application for Windows Phone, and I am trying to make it so that if the remaining time on the timer is zero, a sound from a BackgroundAudioPlayer will play, regardless of whether or not the application is active, inactive, or under lock.

Currently, my issue is that the tick events don't actually do anything while the application isn't active. As soon as the user goes back into the application, the tick events run to the point that they would've otherwise, but the sound effect (or anything else) wont actually play unless the application is active, or switches to being active.

I do have in my Page.xaml.cs:

PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;

The relevant code is:

    void dispatcherTimer_Tick(object sender, EventArgs e)
    {
        var remaining = this.EndTime - DateTime.Now;
        int remainingSeconds = (int)remaining.TotalSeconds;
        this.timeSpan.Value = TimeSpan.FromSeconds(remainingSeconds);

        if (remaining.TotalSeconds <= 0)
        {
            this.dispatcherTimer.Stop();
            button1.Visibility = Visibility.Collapsed;
            button6.Visibility = Visibility.Visible;
            this.EndTime = DateTime.MinValue;
            this.timeSpan.Value = TimeSpan.FromSeconds(0);
            BackgroundAudioPlayer.Instance.Play();
        }
    }

What can I do to make the tick events run while the application is under the lockscreen, or other wise not active?

1 Answers1

0

Windows Phone has strict limits on background working. May be you need permission to work under lockscreen?

http://developer.nokia.com/community/wiki/Run_Windows_Phone_application_under_lock_screen

But it only stays application active under lockscreen, but not when user press windows or closes your app.

ad1Dima
  • 3,185
  • 2
  • 26
  • 37
  • 1
    I did that, and it does now work while under the lock screen, but not while the app isn't active. I assume that complete background working is limited to first party applications then. – ictuateAnomaly Mar 25 '14 at 21:38
  • DispatchTimer runs on the UI Thread hence System.Timers.Timer may be a better option (I haven't test this but seems a likely cause) – Adam Feb 04 '16 at 02:29
  • @AdamPedley there is working with buttons so it must be on UI thread – ad1Dima Feb 15 '16 at 06:39