ENH:add protection in threads

jira:[for random crash]

Change-Id: I6286012dd77abccba461f7cd72a6fc531a84c95f
This commit is contained in:
tao wang
2023-10-31 21:02:41 +08:00
committed by Lane.Wei
parent eb9cc0c9e5
commit eaa7abf518
8 changed files with 66 additions and 46 deletions

View File

@@ -242,21 +242,26 @@ void SelectMObjectPopup::Popup(wxWindow* WXUNUSED(focus))
if (wxGetApp().is_user_login()) {
if (!get_print_info_thread) {
get_print_info_thread = new boost::thread(Slic3r::create_thread([&] {
get_print_info_thread = new boost::thread(Slic3r::create_thread([this, token = std::weak_ptr(m_token)] {
NetworkAgent* agent = wxGetApp().getAgent();
unsigned int http_code;
std::string body;
int result = agent->get_user_print_info(&http_code, &body);
if (result == 0) {
m_print_info = body;
}
else {
m_print_info = "";
}
wxCommandEvent event(EVT_UPDATE_USER_MLIST);
event.SetEventObject(this);
wxPostEvent(this, event);
}));
wxGetApp().CallAfter([token, this, result, body]() {
if (token.expired()) {return;}
if (result == 0) {
m_print_info = body;
}
else {
m_print_info = "";
}
wxCommandEvent event(EVT_UPDATE_USER_MLIST);
event.SetEventObject(this);
wxPostEvent(this, event);
});
}));
}
}