Shows how to use xtd:: iasync_result interface.
#include <xtd/console>
#include <xtd/iasync_result>
#include <xtd/threading/thread>
class async_demo {
public:
string test_method(int call_duration, int* thread_id) {
console::write_line("Test method begins.");
thread::sleep(call_duration);
*thread_id = thread::current_thread().managed_thread_id();
return string::format("My call time was {}.", call_duration);
}
};
using async_method_caller = delegate<
string(
int call_duration,
int* thread_id)>;
auto main() -> int {
auto thread_id = 0;
auto ad = async_demo {};
auto caller = async_method_caller {ad, &async_demo::test_method};
auto result = caller.begin_invoke(3000, &thread_id);
thread::sleep(0);
console::write_line("Main thread {} does some work.", thread::current_thread().managed_thread_id());
result->async_wait_handle().wait_one();
auto return_value = caller.end_invoke(result);
result->async_wait_handle().close();
console::write_line("The call executed on thread {}, with return value \"{}\".", thread_id, return_value);
}
Represents text as a sequence of character units.
Definition basic_string.h:79
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:11
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10