Search code examples
microsoft-band

Unable to connect to Microsoft band from Background Task


I'm using MS Band SDK version 1.3.10518, when I try to init the band client from Background Task I got:

BACKGROUNDTASKHOST.EXE' has exited with code 1

The crash happens after the following line of code:

Dim bands = Await Microsoft.Band.BandClientManager.Instance.GetBandsAsync()

I'm able to connect to the band from the main application on windows phone 8.1 developer preview.

Band Build Version: 10.3.3213.0 09 R


Solution

  • I found the solution related to Await in the Sub Run, the solution consists of using : taskInstance.GetDeferral

    Public Async Sub Run(taskInstance As Background.IBackgroundTaskInstance) Implements Background.IBackgroundTask.Run
            Dim deferral = taskInstance.GetDeferral
            Dim bands = Await Microsoft.Band.BandClientManager.Instance.GetBandsAsync
              'Other work ...
                End Using
           deferral.Complete()
        End Sub
    

    In addition you need to get user consent from the main application as follow:

    bandClient.SensorManager.HeartRate.GetCurrentUserConsent
    

    Thanks for: HttpClient GetAsync fails in background task on Windows 8