I was writing some code and hit an error when doing heavy parallelism over an IVectorView<StorageFile^>^>
. The Debug output was:
First-chance exception at 0x76e86118 in tool.exe: 0x40080201: WinRT originate error.
First-chance exception at 0x76e86118 in tool.exe: Microsoft C++ exception: Platform::FailureException ^ at memory location 0x02daec60.
The code goes something like:
task<vector<long long>> GetDatesTakenFromFiles(IVectorView<StorageFile^>^ filesInFolder)
{
vector<task<long long>> datesTakenTasks;
for each (auto file in filesInFolder)
{
datesTakenTasks.push_back(
create_task(file->Properties->GetImagePropertiesAsync())
.then([=](FileProperties::ImageProperties^ properties) {
return properties->DateTaken.UniversalTime;
})
);
}
return when_all(begin(datesTakenTasks), end(datesTakenTasks));
}
After some investigation, I found out that referencing the file
object from inside the inner lambda would make it work:
task<vector<long long>> GetDatesTakenFromFiles(IVectorView<StorageFile^>^ filesInFolder)
{
vector<task<long long>> datesTakenTasks;
for each (auto file in filesInFolder)
{
datesTakenTasks.push_back(
create_task(file->Properties->GetImagePropertiesAsync())
.then([=](FileProperties::ImageProperties^ properties) {
// I don't know why, but the file was being cleaned up. This prevents it.
UNREFERENCED_PARAMETER(file);
return properties->DateTaken.UniversalTime;
})
);
}
return when_all(begin(datesTakenTasks), end(datesTakenTasks));
}
As a side note, I have to comment that this error only happened when iterating using FolderDepth::Shallow
, but not FolderDepth::Deep
.
User contributions licensed under CC BY-SA 3.0