locked
Asynchronous programming in C++ questions

    Question

  • Hi all,

     Here is a Asynchronous programming in C++ at 

    http://msdn.microsoft.com/en-US/library/windows/apps/hh780559


    void
    WinRTComponent::DeleteWithTasks(String^ fileName) { StorageFolder^ documentsFolder = KnownFolders::DocumentsLibrary; task<StorageFile^> getFileTask(documentsFolder->GetFileAsync(fileName)); getFileTask.then([](StorageFile^ storageFileSample) ->IAsyncAction^ { return storageFileSample->DeleteAsync(); }).then([](void) { OutputDebugString(L"File deleted."); }); }

    Could anybody help explain:

    (1) what does "->IAsyncAction^" mean? is it the return value?

    (2) can we decide the return value of the lambda? or it is defined by MSFT API?


    Qiusheng Xie

    Tuesday, May 29, 2012 12:52 PM

Answers

  • IAsyncAction^ is the return type of the lambda.

    The lambda could be written to return any type (the second one which calls OutputDebugString is a void), but in order to cascade with .then we want it to return a an task<> or something which can be converted to one, such as IAsyncAction^ or IAsyncOperation<>^. Since StorageFile::DeleteAsync() returns IAsyncAction^ and we're just passing that along, our lambda needs to return the same type

    • Marked as answer by Qiusheng Xie Wednesday, May 30, 2012 1:44 AM
    Tuesday, May 29, 2012 4:55 PM
    Owner

All replies

  • IAsyncAction^ is the return type of the lambda.

    The lambda could be written to return any type (the second one which calls OutputDebugString is a void), but in order to cascade with .then we want it to return a an task<> or something which can be converted to one, such as IAsyncAction^ or IAsyncOperation<>^. Since StorageFile::DeleteAsync() returns IAsyncAction^ and we're just passing that along, our lambda needs to return the same type

    • Marked as answer by Qiusheng Xie Wednesday, May 30, 2012 1:44 AM
    Tuesday, May 29, 2012 4:55 PM
    Owner
  • Thanks a lot.

    Qiusheng Xie

    Wednesday, May 30, 2012 1:44 AM
  • see this blog http://www.cnblogs.com/zjjcy/, maybe you can get some help.

    NEU_ShieldEdge

    Wednesday, May 30, 2012 7:31 AM