Share via

GetFileAsync not compatible with unsafe?

Gavin Williams 781 Reputation points
2021-03-11T01:23:27.413+00:00

I'm trying to load files for DirectX resources.

cs
file = await Package.Current.InstalledLocation.GetFileAsync(path);

But I can't await in an unsafe context. How am I meant to load files?

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments

Answer accepted by question author

Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,871 Reputation points
2021-03-11T03:50:27.817+00:00

Hello, Welcome to Micorosoft Q&A,

But I can't await in an unsafe context.

I'm afraid you can't use await in unsafe block and it is by design. for your requirement, we suggest get the file synchronization like the following,

private unsafe void LoadMethod()  
{  
    var file = Getfile().Result;  
}  
private Task<StorageFile> Getfile()  
{  
    return Task.Run(async () =>  
    {  
  
        return await Package.Current.InstalledLocation.GetFileAsync("items");  
  
    });  
}  

If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.