在Xamarin Essentials上使用安全存储时,通用Windows平台应用程序会冻结

问题描述 投票:0回答:1

我正在使用Xamarin Essentials添加安全存储,但每次我尝试保存在通用Windows平台(UWP)上时应用程序都会保持冻结(没有错误)。有人可以解释为什么它会冻结吗?

注意:我在Android设备上使用它没有任何问题。

try
{
   await SecureStorage.SetAsync("username", Username.Text);
   await SecureStorage.SetAsync("password", Password.Text);
}
catch (Exception){}

根据这个form,在UWP上使用安全存储之前不需要设置。

xamarin uwp xamarin.uwp
1个回答
0
投票

线程被锁定所以我不得不添加Device.BeginInvokeOnMainThread所以代码最终看起来像这样:

try
{
  Device.BeginInvokeOnMainThread(async () =>{
   await SecureStorage.SetAsync("username", Username.Text);
   await SecureStorage.SetAsync("password", Password.Text);
  });
}
catch (Exception){}
© www.soinside.com 2019 - 2024. All rights reserved.