This project is read-only.

task_with_progress class

defined in header <pplpp.h>, windows store app only.
template <typename ResultType, typename ProgressType>
class task_with_progress

Public Constructors:

Name: Description
task_with_progress(std::function<ResultType(concurrency:: progressreporter<ProgressType>)> func,cancellationtoken token = cancellationtoken::none()) Construct from a functor taking progressreporter. The user functor that will be scheduled on this task. This functor must provide progress information. The signature of this functor must be ResultType(concurrency::progress_reporter<ProgressType>).
task_with_progress(Windows::Foundation::IAsyncActionWithProgress<ProgressType>^ arg, concurrency::cancellationtoken token = concurrency::cancellationtoken::none()) Construct a “task_with_progress” object from “IAsyncActionWithProgress”.
task_with_progress (Windows::Foundation::IAsyncOperationWithProgress<typename VoidToInt<ResultType>::type, ProgressType>^ arg, concurrency::cancellationtoken token = concurrency::cancellationtoken::none()) Construct a “task_with_progress” object from “IAsyncOperationWithProgress”

Public Methods:

Name: Descriptions:
void on_progress(std::function<void (ProgressType)> callback) Subscribe progress report by registering callback functor. The callback functor which will be invoked each time progress fired. The signature of this functor must be “void (ProgressType)”. The callback functor will be called the same apartment as “on_progress” called. This function could be invoked multiple times to make multiple subscriptions.
operator concurrency::task<ResultType> () const convert “task_with_progress<ResultType, ProgressType>” to task
other methods in concurrency::task refer to http://msdn.microsoft.com/en-us/library/hh750113.aspx

Object Creation Functions:

Name: Descriptions:
task_with_progress<void, ProgressType> create_task_with_progress(Windows::Foundation::IAsyncActionWithProgress<ProgressType>^ action, concurrency::cancellationtoken token = concurrency::cancellationtoken::none()) Creates a task_with_progress object from the “IAsyncActionWithProgress”. It is provided mainly for convenience, because it allows use of the auto keyword while creating tasks.
task_with_progress<ResultType, ProgressType> create_task_with_progress(Windows::Foundation::IAsyncOperationWithProgress<ResultType, ProgressType>^ operation, concurrency::cancellation_token token = concurrency::cancellation_token::none()) Creates a task_with_progress object from the “IAsyncOperationWithProgress”
auto create_task_with_progress(Functor func, concurrency::cancellation_token token = concurrency::cancellation_token::none()) -> decltype (details::create_task_with_progress_impl(func, token)) Creates a task_with_progress object from the functor. This functor should be ResultType(concurrency::progress_reporter<ProgressType>)

Sample 1

concurrency::event ev;
pplpp::task_with_progress<float, int> tp = pplpp::create_task_with_progress([&ev](concurrency::progress_reporter<int> p) {
       ev.wait();
       for (int i = 1; i <= 100; i++)
           p.report(i);
       return 3.0f;
});
auto id = std::this_thread::get_id();
int sum1 = 0, sum2 = 0;
tp.on_progress([&](int progress) {
      sum1 += progress;
      Assert::AreEqual(id.hash(), std::this_thread::get_id().hash());
});
tp.on_progress([&](int progress) {
      sum2 += progress;
      Assert::AreEqual(id.hash(), std::this_thread::get_id().hash());
});
ev.set();

Sample 2

concurrency::event ev;
Windows::Foundation::IAsyncActionWithProgress<int> ^action = concurrency::create_async([&](concurrency::progress_reporter<int> p) {
      ev.wait();
      for (int i = 1; i <= 100; i++)
           p.report(i);
});

pplpp::task_with_progress<void, int> tp1 = pplpp::create_task_with_progress(action);

int sum1 = 0, sum2 = 0;
tp1.on_progress([&](int progress) {
       sum1 += progress;
});
tp1.on_progress([&](int progress) {
       sum2 += progress;
});
ev.set();

Sample 3

Windows::Foundation::IAsyncOperationWithProgress<float, int> ^op = concurrency::create_async([&](concurrency::progress_reporter<int> p) {
      ev.wait();
      for (int i = 1; i <= 100; i++)
          p.report(i);
      return 3.0f;
});

pplpp::task_with_progress<float, int> tp2 = pplpp::create_task_with_progress(op);
sum1 = 0, sum2 = 0;
tp2.on_progress([&](int progress) {
      sum1 += progress;
});
tp2.on_progress([&](int progress) {
      sum2 += progress;
});
ev.set();

Last edited Jul 8, 2013 at 10:45 PM by gbb21, version 7

Comments

No comments yet.