gpt4 book ai didi

c# - 在 Windows Phone 上启动 pdf 文件时出现 System.Runtime.InteropServices.COMException

转载 作者:可可西里 更新时间:2023-11-01 03:11:07 26 4
gpt4 key购买 nike

我正在尝试使用我之前在另一个应用程序中使用的以下工作代码打开 pdf 文件,

但这次当流到达此行时我得到 System.Runtime.InteropServices.COMException:Windows.System.Launcher.LaunchFileAsync(pdffile);

这个异常是什么意思,如何摆脱它?

请注意,在不关心此异常(禁用它)的情况下,

文件还是打不开

请注意:该文件存在于我的隔离文件夹中(使用 wpowertool 检查),

我尝试了 2 个不同的文件,所以这应该不是文件损坏的问题。

    public void openFile(string options)
{
System.Diagnostics.Debug.WriteLine("options: " + options);
string optVal = JsonHelper.Deserialize<string[]>(options)[0];
asyncOpen(optVal);
}

public async Task asyncOpen(string filename)
{
filename = filename.Substring(2, filename.Length - 2);
filename = filename.Replace("//", "/").Replace("/", "\\");
Windows.Storage.StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
Debug.WriteLine("local: " + local.Path);
Windows.Storage.StorageFile pdffile = await local.GetFileAsync(filename);
Debug.WriteLine("pdffile: " + pdffile.Name);
//// Launch the pdf file.
Windows.System.Launcher.LaunchFileAsync(pdffile);
}

这个MSDN post属于我。是的,文件已安装并且我有 acrobat reader。

请注意,此 C# 代码是 phonegap/cordova plugin在我的混合应用程序中通过 javascript 调用。

最佳答案

注意这个MSDN Article - Launcher.LaunchFileAsync(IStorageFile)里面的备注:

The calling app must be visible to the user when the API is invoked.
This API must be called from an ASTA thread (also known as a UI thread).


非常感谢 OP 分享解决方案。以下代码应该可以帮助其他人解决此问题:

Deployment.Current.Dispatcher.BeginInvoke(() => { asyncOpenFile(options); }); 

关于c# - 在 Windows Phone 上启动 pdf 文件时出现 System.Runtime.InteropServices.COMException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31246020/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com