locked
blocking a call till an asynchronous method returns.

    Question

  • I have a series of operations that needs to be done sequentially inside a method.

    each operation inturn runs an asynchronous call and its results needs to be  passed to the next operation.

     

    right now iam just nesting this inside lambdas and having the individual operation at the completed handler of the previous one. This solves the problem but it looks bit ugly.

    Is there any better way of handling this ?


    • Edited by Noviez Tuesday, January 17, 2012 6:17 PM
    Tuesday, January 17, 2012 6:17 PM

Answers

  • Take a look at the PPL libraries for a cleaner async implementation.

    The Windows 8 Asynchrony with PPL blog explains it and has a file access sample.

    Synchronizing the calls can be useful on a worker thread, but your users will thank you if you don't hang your UI thread by blocking waiting for asynch calls to complete.

    --Rob

     

    • Marked as answer by Noviez Wednesday, January 25, 2012 11:14 AM
    Tuesday, January 17, 2012 7:35 PM
    Owner

All replies

  • Hi, take a look at CoWaitForMultipleObjects

    http://msdn.microsoft.com/en-us/library/windows/desktop/hh404144%28v=vs.85%29.aspx

    Tuesday, January 17, 2012 6:43 PM
  • Hi, Is the cowaitformultipleobjects supported in metro ?

    what iam looking for is something similar to the fileaccess example in the metro sample collection. That example just nests the lambda to acheive a sequence of operation (the write operation in the sample). and i only see the same pattern in other samples as well. Is there any better approach here ?

    Tuesday, January 17, 2012 7:24 PM
  • Take a look at the PPL libraries for a cleaner async implementation.

    The Windows 8 Asynchrony with PPL blog explains it and has a file access sample.

    Synchronizing the calls can be useful on a worker thread, but your users will thank you if you don't hang your UI thread by blocking waiting for asynch calls to complete.

    --Rob

     

    • Marked as answer by Noviez Wednesday, January 25, 2012 11:14 AM
    Tuesday, January 17, 2012 7:35 PM
    Owner
  • Hi,  iam right now using the ppl tasks and it pretty  much solves my problem. Iam using ppl preview header from the sample as it gives ability to create async tasks instead from the one in the sdk.

    Looks liek it using a restricted COM api unlike the one from the sdk.  will this be fixed in the final revision. ( i do see comment before the _ContextCallback class that it will be using raw com for the time being)

    Tuesday, January 31, 2012 2:25 AM