none
UI thread and task_continuation_context::use_current() RRS feed

  • Question

  • Looks like in nested .then task_continuation_context::use_current() actually does not point to UI thread.

    Any way to explicitly specify the UI thread?

    Or what is the right way to do this one:

    create_task([this](){
       concurrent_vector<task<int>> tasks;
       tasks.push_back(create_task([]()->int{return 1;}));
       tasks.push_back(create_task([]()->int{return 2;}));
       when_all(begin(tasks), end(tasks))
          .then([this](vector<int> results) {
              this->MyListView->Items->Append(L"All tasks completed!");
          },task_continuation_context::use_current());
    });

    Thursday, November 22, 2012 9:13 PM

Answers

  • Figured out the answer myself, was quite simple, hope will help the other nubs:

    auto ui = task_continuation_context::use_current();
    create_task([this,ui](){
       concurrent_vector<task<int>> tasks;
       tasks.push_back(create_task([]()->int{return 1;}));
       tasks.push_back(create_task([]()->int{return 2;}));
       when_all(begin(tasks), end(tasks))
          .then([this](vector<int> results) {
              this->MyListView->Items->Append(L"All tasks completed!");
          },ui);
    });

    • Marked as answer by NubCoder Friday, November 23, 2012 8:51 AM
    Friday, November 23, 2012 8:51 AM

All replies

  • Figured out the answer myself, was quite simple, hope will help the other nubs:

    auto ui = task_continuation_context::use_current();
    create_task([this,ui](){
       concurrent_vector<task<int>> tasks;
       tasks.push_back(create_task([]()->int{return 1;}));
       tasks.push_back(create_task([]()->int{return 2;}));
       when_all(begin(tasks), end(tasks))
          .then([this](vector<int> results) {
              this->MyListView->Items->Append(L"All tasks completed!");
          },ui);
    });

    • Marked as answer by NubCoder Friday, November 23, 2012 8:51 AM
    Friday, November 23, 2012 8:51 AM
  • I was having the exact same issue, thanks for posting the solution. They should really highlight it in bold in the examples to make it clearer, as it's easily missed at first usage.
    Monday, May 13, 2013 3:24 PM