Async Programming Improvements for C++ and UWP

Play Async Programming Improvements for C++ and UWP

The Discussion

  • User profile image

    I have 2 questions. 

    1. Can C++ events be marked as async some how so they can await async functions? For example a XAML button click event.
    2. Can a void function be marked as async without making it as a a task such as done in C# (async void Func())? This would allow non async functions to call the function synchronously while the internal function can still use co_await. Would be useful in modifying existing code without having to modify return types all the way up the call stack.
  • User profile image

    Hi, how to handle exceptions ?

  • User profile image

    Can I get access to these new features con Win8.1 c++/cx projects?

  • User profile image

    Excellent congratulations for the great work!! I'm installing VS2015 Update 2 to play with it! Thank you very much!

  • User profile image

    I think C++98 two-phase template parsing would be a win for compile-time performance. MSVC parses the entire template every time a new instantiation is called for. Clang and GCC parse the non-dependent parts of a template only once.

  • User profile image

    @dea398: Yes, but only from VS2015, Update2 is better as we reinforce Coroutines in it

  • User profile image


    There are two ways of doing events:

    1. Create a task<void> EventHandlerImpl(int p) { ... co_await ... } and have a simple forwarder:

    void EventHandler(int p) { EventHandlerImpl(p); }

    2. Specialize std::experimental::coroutine_traits<void, Whatever...> to be the same as std::experimental::coroutine_traits<concurrency::tasl<void>, Whatever...> with the exception of get_return_object. This will allow you to author coroutines return void type. It can look something like:

    namespace std { namespace experimental {
      template <typename... Whatever>
      struct coroutine_traits<void, Whatever...> {
        using base = typename coroutine_traits<concurrency::task<void>, Whatever...>::promise_type;
        struct promise_type : base { void get_return_object() { base::get_return_object(); } };

    Now you can simply write:

    void Handler1(int p) { ... } // normal function

    void Handler2(int p) { .... co_await ... } // coroutine






  • User profile image


    set_exception member of coroutine promise_type controls the behavior what to do if exception escapes the coroutine.

    If set_exception is not present, exception propagates through the call stack normally. (std::experimental::generator behavior)

    If set_exception is present, exception is stopped and given to the eventual consumer, for example a coroutine adapter for ppl tasks or std::future, defines set_exception to be packaged and passed to the consumer who calls .get() on the future/task.


  • User profile image

    hello everyone, how would I write a function like this with coroutines in c++?
    I would like to have a function that I can call over and over and it will generate a successive number.
    something like this...
    int gen(){

    int counter = 0;


    yield counter;



    int main(){

    gen(); // 0

    gen(); // 1 etc.


    I am a c++ newbie, but the talk of coroutines, specifically the ones Gor is speaking of, are exciting!

  • User profile image

    First of all, thank you for the amazing work!

    But UpdateData() below fails because the continuation doesn't run on the awaiter thread (main gui thread). What do I customize in PPL to have an automatic thread context switch, please?

    ... DDX_Text(pDX, IDC_EDIT1, m_CalculationResult); ...

    int calculateInt()
    return 42;

    task<int> calcBigValueAsync()
    return create_task([] { return calculateInt(); });

    void MfcDialog::OnBnClickedBtnStartcalc()

    task<void> MfcDialog::OnBnClickedBtnStartcalcImpl()
    m_CalculationResult = co_await calcBigValueAsync();
    UpdateData(FALSE); // !!! background thread can't access IDC_EDIT1 editbox

Add Your 2 Cents