Skip to content

Commit

Permalink
debug_form and trace_form are now "thread safe".
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Oct 7, 2023
1 parent a83448a commit 4e09c65
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/xtd.forms/src/xtd/forms/trace_form_base.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../../../include/xtd/forms/trace_form_base.h"
#include <xtd/lock>

using namespace xtd;
using namespace xtd::drawing;
Expand Down Expand Up @@ -88,11 +89,17 @@ void trace_form_base::on_fore_color_changed(const event_args& e) {
}

void trace_form_base::write(const ustring& trace) {
if (need_header()) write_header();
data_->text.append_text(trace);
auto writer = [self = this, trace=trace] {
auto lck = lock {*self};
if (self->need_header()) self->write_header();
self->data_->text.append_text(trace);
};
if (invoke_required()) begin_invoke(writer);
else writer();
}

void trace_form_base::write_line(const ustring& trace) {
auto lck = lock {*this};
write(trace);
write(environment::new_line());
need_header(true);
Expand Down

0 comments on commit 4e09c65

Please sign in to comment.