#include <xtd/forms/application>
#include <xtd/forms/form>
#include <xtd/forms/list_box>
#include <xtd/threading/thread>
class form_thread :
public form {
public:
form_thread() {
text("Form and thread example");
form_closed += [&] {
closed = true;
};
messages.parent(*this);
messages.dock(dock_style::fill);
for (auto index = 0_z; index < environment::processor_count() - 1; ++index) {
thread::start_new([&] {
auto counter = 0u;
auto thread_name = string::format("thread {}", thread::current_thread().managed_thread_id());
thread::current_thread().name(thread_name);
while (!closed) {
thread::sleep(50_ms);
++counter;
messages.begin_invoke([&, counter, thread_name] {
messages.items().push_back(string::format("{}: counter: {}", thread_name, counter));
messages.selected_index(messages.items().size() - 1);
});
}
});
}
}
private:
bool closed = false;
};
auto main() -> int {
application::run(form_thread());
}
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