How to iterate IMapView WinRT object within Javascript UWP application?

138 Views Asked by At

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!

1

There are 1 best solutions below

0
On

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.