Trying to list background applications - System.UnauthorizedAccessException

qba_Vqba_V PLMember ✭✭

Hi,
I would like get list of background apps running on UWP platform.

So i have - sharedProject and UWP project.
In SharedProject I created a DependencyService which is calling method in UWP project to get list of apps:

DependencyService:
DependencyService.Get<IBackgroundAppsInfo>().GetBeackgroundProcesses();

Method in UWPProject :
`public BatteryMobileSaver.ViewModels.SharedViewModel GetBeackgroundProcesses()
{
GetAppInfo();
LoadProcesses();
foreach(var process in uwpNativeViewModel.ProcessList)
{
sharedViewModel.ProcessList.Add(new BatteryMobileSaver.Models.ProcessInfoModel
{
CpuUsageTime = process.CpuUsageTime,
DiskBytesCount = process.DiskBytesCount,
ExeName = process.ExeName,
PageFileSize = process.PageFileSize,
ProcessId = process.ProcessId,
WorkingSetSize = process.WorkingSetSize
});
}
return sharedViewModel;
}

    public async void GetAppInfo()
    {
        IList<AppDiagnosticInfo> list = await AppDiagnosticInfo.RequestInfoAsync();
        list.ToList().ForEach(o => sharedViewModel.AppInfoList.Add(new BatteryMobileSaver.Models.AppInfoModel
        {
            DisplayName = o.AppInfo.PackageFamilyName,
        }));
    }`

Data are returned correctly, but then i get Exception:

Exception = {System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

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

Is that problem with async/await operation ?
Could You please post a solution for that problem ?

Thanks, a lot

Sign In or Register to comment.