I need some help on how to properly handle IO in an RT app without blocking the UI thread.
I have something like:
create_task(FileIO::ReadBufferAsync(file)).then(
[Load](task<IBuffer^> bufferTask)
{
try
{
IBuffer^ buffer = bufferTask.get();
DataReader^ reader = DataReader::FromBuffer(buffer);
Load(reader);
return;
}
catch (Platform::COMException ^e)
{
// ...
}
});
Where Load is a lambda that I can pass in to load the data.
The problem is that everything in the task's lambda seems to be executing on the UI thread. I was assuming that the continuation of ReadBufferAsync would be on a separate thread, but this does not seem to be the case.
What's happening here? How is it that that Load(reader) is getting called on the UI thread, and what is the correct way to handle file IO off of the UI thread. Should I just spawn & detach a "loading" thread before doing this,
or am I missing something?
Thanks!