我在C ++ / CX中使用UWP API的CreateFileAsync方法时遇到问题。 这是我试图执行的代码:
create_task(folder->CreateFileAsync(destination_file, Windows::Storage::CreationCollisionOption::OpenIfExists)).
then(
[this](StorageFile^ dest_file)
{
//do something here
});
CreateFileAsync的调用似乎成功,因为我的文件是在适当的位置创建的。
但是,我的lambda函数(//do something here
)中的代码永远不会被执行。
有人能解释我的错误吗?
答案 0 :(得分:0)
CreateFileAsync的调用似乎成功,因为我的文件是在适当的位置创建的。但是,我的lambda函数中的代码(//在这里执行某些操作)永远不会执行。
我无法在我身边重现您的问题。您已使用create_task
执行CreateFileAsync
异步方法。 .then
块可以视为回调函数。它将在CreateFileAsync
完成后执行。您可以编写以下代码来验证它是否已执行。
create_task(folder->CreateFileAsync("test.jpg", Windows::Storage::CreationCollisionOption::OpenIfExists)).
then(
[this](StorageFile^ dest_file)
{
OutputDebugString(L"excuted------->");
});
有关详情,请参阅Asynchronous programming in C++。