locked
WinRT - How to properly handle a C lib async callback

    Question

  • I am porting a C library to a WinRT component.  The C lib implements asynchronous callbacks.  The model is you call a said synchronous function, and during the execution the asynchronous callback is called n times.  Once the synchronous function exits the asynchronous callback will not be called.  So what is the best way to handle this?  Do I need to redesign the C library such that I use parallel tasks as per most of the examples I have found, or can I asynchronously update the UI thread.  It seems to me the UI thread blocks on the WinRT method call.  Thanks!

    
    Tuesday, December 16, 2014 6:29 PM

Answers

  • I figured it out.  I used the MSFT WinRT CPP walk through using prime numbers in conjunction with the answer in the link below to find my solution.

    http://stackoverflow.com/questions/14218091/how-to-convert-from-ref-pointer-to-raw-pointer

    Thursday, December 18, 2014 1:46 AM

All replies

  • Hi lil'sprout,

    >> The model is you call a said synchronous function, and during the execution the asynchronous callback is called n times.  Once the synchronous function exits the asynchronous callback will not be called.

    I’m not sure whether I understand your requirement correctly, do you mean the synchronous function needed to wait all of the callbacks completing before exiting?

    Please let me know if I have any misunderstandings.

    >> can I asynchronously update the UI thread

    You can use the Dispatcher to update the UI asynchronously.

    Sample Code: Thread pool sample (C++ or C#)

    This sample shows you how to run work items asynchronously using the Windows Runtime thread pool API.

    And here is an article for your reference:

    # Async programming patterns and tips in Hilo (Windows Store apps using C++ and XAML)

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 17, 2014 7:29 AM
  • I figured it out.  I used the MSFT WinRT CPP walk through using prime numbers in conjunction with the answer in the link below to find my solution.

    http://stackoverflow.com/questions/14218091/how-to-convert-from-ref-pointer-to-raw-pointer

    Thursday, December 18, 2014 1:46 AM