什么可能导致Launcher.LaunchFileAsync间歇性失败

时间:2014-10-01 18:49:42

标签: windows-store-apps storagefile

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

var launcherOption = new LauncherOptions();
launcherOption.DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.Default;
launcherOption.DisplayApplicationPicker = userSettings.ShowApplicationPicker;

bool success;
// fileResponse.File is a StorageFile object
if (fileResponse.OpenAs == ContentOpenOption.LocalFile)
    success = await Launcher.LaunchFileAsync(fileResponse.File, launcherOption);
else
    success = await Launcher.LaunchUriAsync(fileResponse.WebUri, launcherOption);

我检查过的事情:

  • 该文件不受Windows限制(例如:我正在测试txt,jpg文件,而不是exe,bin,bat)
  • 我的应用程序在此次通话时可见
  • 使用以下代码在UI线程上进行调用:
var launcherOption = new LauncherOptions();
                    launcherOption.DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.UseHalf;
                    launcherOption.DisplayApplicationPicker = userSettings.ShowApplicationPicker;

                    var dispatcherObject = CoreApplication.MainView.CoreWindow.Dispatcher;
                    if (dispatcherObject != null && dispatcherObject.HasThreadAccess == false)
                    {
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                                Windows.UI.Core.CoreDispatcherPriority.Normal,
                                async () =>
                                {
                                    if (fileResponse.OpenAs == ContentOpenOption.LocalFile)
                                        success = await Launcher.LaunchFileAsync(fileResponse.File, launcherOption);
                                    else
                                    {
                                        launcherOption.TreatAsUntrusted = true;
                                        success = await Launcher.LaunchUriAsync(fileResponse.WebUri, launcherOption);
                                    }
                                });
                    }
                    else
                    {
                        if (fileResponse.OpenAs == ContentOpenOption.LocalFile)
                            success = await Launcher.LaunchFileAsync(fileResponse.File, launcherOption);
                        else
                        {
                            launcherOption.TreatAsUntrusted = true;
                            success = await Launcher.LaunchUriAsync(fileResponse.WebUri, launcherOption);
                        }
                    }

                    if (!success)
                    {
                        content.IsContentUpdating = false;
                        content.ContentStatus = string.Empty;
                        logger.LogMessage(string.Format("Unable to open file. {0}",   
                        content.Name), LoggingLevel.Error);
                   }
   }
  • 确保通过检查文件的属性来阻止该文件。

我在这里可能缺少什么其他想法?

0 个答案:

没有答案