#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);
}
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:11
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10