我正在尝试读取我放入APPs Assets目录中的一些Sprite数据(我自己的数据文件类型)。 这是部分无效的代码:
using namespace Windows::Storage;
using namespace concurrency;
using namespace Platform;
String^ fileName = "Assets\\testSprite.ssp";
String^ path = "";
StorageFolder^ InstallationFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;
auto asyncOperation = InstallationFolder->GetFileAsync(fileName);
auto getFileTask = create_task(asyncOperation);
getFileTask.then([&path](task<StorageFile^> task)
{
try
{
StorageFile^ myStorageFile = task.get();
// .get() didn' t throw, so we succeeded.
OutputDebugString(L"File exists.");
path = myStorageFile->Path;
}
catch (Platform::COMException^ e)
{
//Example output: The system cannot find the specified file.
OutputDebugString(e->Message->Data());
}
}).get();
// this line exists to check the path result, i put a breakpoint on it.
path += "";
尽管我将try / catch块放在那里,程序实际上还是崩溃了。
这是我在调试模式下遇到的错误:
Exception levée à 0x00007FFA07AC9129 dans Dungeons of Nargoth.exe : exception Microsoft C++ : Concurrency::invalid_operation à l'emplacement de mémoire 0x0000008809CFCB38.
Exception non gérée à 0x00007FF9BB84AFAC (ucrtbased.dll) dans Dungeons of Nargoth.exe : Un paramètre non valide a été passé à une fonction qui considère les paramètres non valides comme une cause d'erreur irrécupérable.
我已验证该文件位于正确的目录中。 它位于:
"Dungeons of Nargoth\x64\Debug\Dungeons of Nargoth\AppX\Assets\testSprite.ssp"
编辑: 当我删除.get()后,catch块就起作用了。但是我该如何等待操作结果呢?