Windows store apps 什么会导致Launcher.LaunchFileAsync间歇性失败

Windows store apps 什么会导致Launcher.LaunchFileAsync间歇性失败,windows-store-apps,storagefile,Windows Store Apps,Storagefile,在我的windows应用商店应用程序中,我允许用户打开本地不存在的文件,然后应用程序将下载该文件并将其保存到应用程序的本地文件夹中,然后尝试使用以下代码打开该文件。 这会间歇性工作,其他时候调用返回false var-launchoption=new-launchoptions(); launcherOption.DesiredRemainingView=Windows.UI.ViewManagement.ViewSizePreference.Default; LaunchOption.Disp

在我的windows应用商店应用程序中,我允许用户打开本地不存在的文件,然后应用程序将下载该文件并将其保存到应用程序的本地文件夹中,然后尝试使用以下代码打开该文件。 这会间歇性工作,其他时候调用返回false

var-launchoption=new-launchoptions();
launcherOption.DesiredRemainingView=Windows.UI.ViewManagement.ViewSizePreference.Default;
LaunchOption.DisplayApplicationPicker=userSettings.ShowApplicationPicker;
成功;
//File是一个StorageFile对象
if(fileResponse.OpenAs==ContentOpenOption.LocalFile)
success=wait Launcher.LaunchFileAsync(fileResponse.File,Launcher选项);
其他的
success=wait Launcher.launchurisync(fileResponse.WebUri,Launcher选项);
我检查过的东西:

  • 该文件不受windows限制(例如:我正在测试txt、jpg文件,而不是exe、bin、bat)
  • 我的应用程序在拨打此电话时可见
  • 通过使用以下代码在UI线程上进行调用:
var-launchoption=new-launchoptions();
launcherOption.DesiredRemainingView=Windows.UI.ViewManagement.ViewSizePreference.UseHalf;
LaunchOption.DisplayApplicationPicker=userSettings.ShowApplicationPicker;
var dispatcherObject=CoreApplication.MainView.CoreWindow.Dispatcher;
if(dispatcherObject!=null&&dispatcherObject.HasThreadAccess==false)
{
等待CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
Windows.UI.Core.CoreDispatcherPriority.Normal,
异步()=>
{
if(fileResponse.OpenAs==ContentOpenOption.LocalFile)
success=wait Launcher.LaunchFileAsync(fileResponse.File,Launcher选项);
其他的
{
launcheoption.TreatAsUntrusted=true;
success=wait Launcher.launchurisync(fileResponse.WebUri,Launcher选项);
}
});
}
其他的
{
if(fileResponse.OpenAs==ContentOpenOption.LocalFile)
success=wait Launcher.LaunchFileAsync(fileResponse.File,Launcher选项);
其他的
{
launcheoption.TreatAsUntrusted=true;
success=wait Launcher.launchurisync(fileResponse.WebUri,Launcher选项);
}
}
如果(!成功)
{
content.isContentUpdate=false;
content.ContentStatus=string.Empty;
logger.LogMessage(string.Format(“无法打开文件{0}”),
content.Name),LoggingLevel.Error);
}
}
  • 通过检查文件的属性,确保该文件未被windows阻止

还有什么其他想法吗?

您没有列出下载代码,但请确保文件已实际完成下载。这可能会导致间歇性故障,具体取决于文件大小、时间等。我正在使用BackGroundDownloader并等待它完成。即使它失败了,那么我现在应该能够打开它的下一次,因为文件现在缓存在本地。如果我转到该目录并单击它,我就可以打开它。如果您的代码在ui线程上运行,为什么要使用
Dispatcher.RunAsync
?我认为
Dispatcher.RunAsync
通常只在工作线程中用于在ui线程上运行东西。这是我尝试过的事情之一,只是为了确保我没有遇到这种情况,原始代码(上面发布的)没有使用它。我猜可能是1)您的原始代码可能没有在ui线程上运行。或者2)您的调度程序为null,您捕获了null ref异常,因此您从未调用过启动程序代码。