I'm attempting to use the Windows 10 runtime Bluetooth Low-energy (BLE) APIs in a Windows desktop WPF
C# application. The code is mostly based off of the Bluetooth Advertisement UWP sample, but I've added the reference to the relevant libraries.
However, I'm running into an issue with the BackgroundTaskRegistration
class.
In my RegisterBackgroundTask
method (essentially identical to this), I attempt to see if my BLE-scanning background task already exists:
foreach (var cur in BackgroundTaskRegistration.AllTasks)
{
if (cur.Value.Name == taskName)
{
// The task is already registered.
return (BackgroundTaskRegistration)(cur.Value);
}
}
But on that first line, calling BackgroundTaskRegistration.AllTasks
gives:
Exception thrown: 'System.Exception' in BLEProximity.exe
Msg: Element not found. (Exception from HRESULT: 0x80070490)
Stack: at Windows.ApplicationModel.Background.BackgroundTaskRegistration.get_AllTasks() at BLEProject.MainWindow.RegisterBackgroundTask(String taskEntryPoint, String taskName, IBackgroundTrigger trigger, IBackgroundCondition condition) in C:\Users\MyUserName\Documents\Visual Studio 2015\Projects\BLEProject\BLEProject\MainWindow.xaml.cs:line 421
Source: Windows.ApplicationModel
If I bypass the above check for the background task's existence, I will get the same error when I call the Register()
method of my BackgroundTaskBuilder
.
Note that I have no issues with any of this code when using it in a UWP
app. For more background, see this related question.
My only guess is that this could be related to the app manifest in some way, but I'm fairly new to Windows app development.
User contributions licensed under CC BY-SA 3.0