Hello,
is it possible to return Task<bool> of the first form above without using async and await
Yes, you can try to use the following code.
public Task<bool> IsEncryptionKeySet(string keyname)
{
bool result = false;
var res = SecureStorage.GetAsync(keyname).Result;
if (!string.IsNullOrEmpty(res))
{
result = true;
}
return Task.FromResult(result);
}
But It is recommended to you to achieve it by using async
and await
. If the value is too long. It will block the UI thread.
public async Task<bool> IsEncryptionKeySet(string keyname)
{
bool result = false;
var res = await SecureStorage.GetAsync(keyname);
if (!string.IsNullOrEmpty(res))
{
result = true;
}
return await Task.FromResult(result);
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.