【发布时间】:2017-06-30 15:40:29
【问题描述】:
/数据/我的文件/
我想在我的 Hololens 应用程序中打开上面的数据路径,它位于我的应用程序文件夹 (HoloApp/Data/myFiles) 的本地。据我了解,这样做的主要方法是使用 FileOpenPickers。我仔细阅读了API's 并试图获得我可以使用的最基本的、精简的、简单的 FOP。
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
Task task = new Task(
async () =>
{
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write access to the picked file
Debug.Log("Picked file: " + file.Name);
}
else
{
Debug.Log("Cancelled");
}
});
task.Start();
task.Wait();
我已经为此苦苦挣扎了一周以上,但运气不佳(我很抱歉在 UWP 应用程序开发中表现得很糟糕。)非常感谢任何建议、链接和鼓励
这是最新的回报:
抛出异常:mscorlib.ni.dll 中的“System.Exception”
程序“[4084] hololensapplication.exe”已退出,代码为 -1073741189 (0xc000027b)。
Microsoft Dev Center 对此错误代码也没有多大帮助。
编辑:
private async void OpenPdfButton_Click()
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.FileTypeFilter.Add(".pdf");
StorageFile file = await openPicker.PickSingleFileAsync();
}
使用
崩溃抛出异常:mscorlib.ni.dll 中的“System.Exception”
程序“[4268] hololensapplication.exe”已退出,代码为 -1073741189 (0xc000027b)。
【问题讨论】:
-
好吧,如果你选择一个文件,大概是因为你需要这个文件,那么为什么要使用异步呢?
-
@Juan 我使用文件选择器找到的所有文档都使用等待和异步。如果这是您的意思,请解释如何使用 w/o。是的,我确实需要文件
-
我假设你是作为点击事件的一部分执行的,对吧?该方法很可能已标记为异步,因此无需使用任务包装执行。删除周围的任务并正常执行代码。 PickSingleFileAsync() 已经是异步的。
-
@Juan 请查看编辑。删除了任务/异步包装,同样的错误。
标签: c# unity3d uwp hololens fileopenpicker