I am writing a small WinRT program to async create a folder and a file. The simplified code is like below:
auto createFolderOp = ApplicationData::Current->LocalFolder->CreateFolderAsync(L"DummyFolder", CreationCollisionOption::OpenIfExists);
create_task(createFolderOp).then([](task<StorageFolder ^> folder)
{
StorageFolder ^tempFolder;
tempFolder = uploadFolder.get();
return tempFolder->CreateFileAsync(L"DummyFile.txt", CreationCollisionOption::ReplaceExisting);
}).then([] (task<StorageFile ^> dummyFile)
{
StorageFile ^file;
file = dummyFile.get();
FileIO::WriteTextAsync(file, L"Dummy Content");
});
During the execution of this code, I want to update my UI on each step. For example I have a textblock and in each step I want to update it to show different text, such as:
Create Folder Succeed...
Create File Succeed...
Write File Succeed...
etc.
How can I access to the UI element from Async task? What is the best practice of doing this?