Stefan V
Stefan V

Reputation: 33

Microsoft Band SDK Preview - NotificationManager within a backgroundtask

Hi I am not sure if I am missing something or whether this is not within the API which seems short sighted in my opinion.

Can the SDK send a notification to the band from within a background task? This seems to be one of the most useful things to me but when I try I get an error. 'bandClient.NotificationManager.SendMessageAsync' is where it throws an exception. The background task is a timer task.

The background code is simple, I tried it on a background and UI thread.

try

            {

                // Get the list of Microsoft Bands paired to the phone.

                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();

                if (pairedBands.Length < 1)

                {

                    deferral.Complete();

                }


                // Connect to Microsoft Band.

                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))

               {


                    await bandClient.NotificationManager.SendMessageAsync(myTileId, "Earnings", currentDollars.ToString(), DateTimeOffset.Now, f);

                }

            }

            catch (Exception ex)

Exception and stack trace:

ex = {System.Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

at Windows.UI.Xaml.Application.get_Current()

at Microsoft.Band.BandClientManager.d__2.MoveNext()

--- End of stack trace from previous location...

at Windows.UI.Xaml.Application.get_Current()

at Microsoft.Band.BandClientManager.d__2.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

at WindowsRuntimeComponent1.AppTileUpdater.d__8.MoveNext()

Upvotes: 1

Views: 974

Answers (2)

Iris Classon
Iris Classon

Reputation: 5842

Backgroundtasks (and quite a few more things) have been sorted in the new release which took the SDK out of preview today.

Upvotes: 0

Phil Hoff -- MSFT
Phil Hoff -- MSFT

Reputation: 2016

Yes, the intention is that you should be able to connect to and manipulate a Band from a background task. However, there is a known issue with the Band SDK Preview (1.3.10219-preview) that prevents the creation of an IBandClient in code running within a background task.

Upvotes: 5

Related Questions