#include <xtd/xtd>
class async_demo {
public:
string test_method(int call_duration, int* thread_id) {
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::int32 managed_thread_id() noexcept
Gets the managed thread id of the current thread.