1

i have a need to iterate the WinRT type of object in order to unregister a UWP background task which i have registered with success.

I have access to this object BackgroundTaskRegistration.AllTasks in javascript but i receive a WinRT collection of type IMapView<Guid, BackgroundTask> which i cannot iterate or access.

NOTE: The solution is setup using Cordova, but i manually connected the WinRT from VS2017.

Any idea is appreciated!

Tim
  • 177
  • 2
  • 13

1 Answers1

0

I tried to do the same thing and found the soltuion. Here is the sample.

        const background = Windows.ApplicationModel.Background;
        const allTasks = background.BackgroundTaskRegistration.allTasks;
        if (allTasks.size > 0) {
          let item = allTasks.first();
          // item.hasCurrent should be false if the item is empty.
          while (item.hasCurrent) {
            const current = item.current;
            const task = current.value;

            // Do something with current task like
            if (task.name === 'name') {
            }

            // move to next
            item.moveNext();
          }
        }

Hope this should work.

weirdan
  • 2,499
  • 23
  • 27