xtd 0.2.0
Loading...
Searching...
No Matches
form_and_thread.cpp

demonstrates how a thread can update ui with xtd::forms::control::invoke method.

Windows

macOS

Gnome

#include <xtd/xtd>
class form_thread : public form {
public:
form_thread() {
text("Form and thread example");
form_closed += delegate_ {
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:
list_box messages;
bool closed = false;
};
auto main() -> int {
application::run(form_thread());
}
#define delegate_
The declaration of a delegate type is similar to a method signature. It has a return value and any nu...
Definition delegate.hpp:900