在网络断开时使用 StoreContext.CanSilentlyDownloadStorePackageUpdates 会导致应用程序崩溃
Using StoreContext.CanSilentlyDownloadStorePackageUpdates when the network is disconnected will cause the app to crash
奇怪,try catch 也捕捉不到这个异常,不知如何是好
代码片段:
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
public bool CanSilentlyUpdate()
{
try
{
// Disable the network before executing this method, and an exception is thrown:
// System.AccessViolationException :“Attempted to read or write protected memory.
// This is often an indication that other memory is corrupt.”
// Then the app crashes
return StoreContext.GetDefault().CanSilentlyDownloadStorePackageUpdates;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return false;
}
}
事件查看器中的一些错误日志:
Application: MyApp.exe Framework Version: v4.0.30319 Description: The
process was terminated due to an unhandled exception. Exception Info:
System.AccessViolationException at
Windows.Services.Store.StoreContext.get_CanSilentlyDownloadStorePackageUpdates()
我知道我可以判断是否调用StoreContext.CanSilentlyDownloadStorePackageUpdatesby
判断网络状态,但是当我使用StoreContext.TrySilentDownloadStorePackageUpdatesAsync
升级应用程序时,如果升级过程中网络被禁用,应用程序仍然会崩溃。
我认为这是同类问题,所以我希望能有更好的方法来解决它。
经过与工程师的讨论,得出目前StoreContext.TrySilentDownloadStorePackageUpdatesAsync
抛出的后台异常无法在UI线程中捕获。
目前推荐的方法是在执行此方法之前检查网络可用性(NetworkInformation.NetworkStatusChanged). When the network status changes, the user is required to perform the download again. Or use the RequestDownloadStorePackageUpdatesAsync方法位于UI线程中执行下载请求。
谢谢。
奇怪,try catch 也捕捉不到这个异常,不知如何是好
代码片段:
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
public bool CanSilentlyUpdate()
{
try
{
// Disable the network before executing this method, and an exception is thrown:
// System.AccessViolationException :“Attempted to read or write protected memory.
// This is often an indication that other memory is corrupt.”
// Then the app crashes
return StoreContext.GetDefault().CanSilentlyDownloadStorePackageUpdates;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return false;
}
}
事件查看器中的一些错误日志:
Application: MyApp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.AccessViolationException at Windows.Services.Store.StoreContext.get_CanSilentlyDownloadStorePackageUpdates()
我知道我可以判断是否调用StoreContext.CanSilentlyDownloadStorePackageUpdatesby
判断网络状态,但是当我使用StoreContext.TrySilentDownloadStorePackageUpdatesAsync
升级应用程序时,如果升级过程中网络被禁用,应用程序仍然会崩溃。
我认为这是同类问题,所以我希望能有更好的方法来解决它。
经过与工程师的讨论,得出目前StoreContext.TrySilentDownloadStorePackageUpdatesAsync
抛出的后台异常无法在UI线程中捕获。
目前推荐的方法是在执行此方法之前检查网络可用性(NetworkInformation.NetworkStatusChanged). When the network status changes, the user is required to perform the download again. Or use the RequestDownloadStorePackageUpdatesAsync方法位于UI线程中执行下载请求。
谢谢。