mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-16 01:52:11 +00:00
ENH:add protection in threads
jira:[for random crash] Change-Id: I6286012dd77abccba461f7cd72a6fc531a84c95f
This commit is contained in:
@@ -429,19 +429,23 @@ void SelectMachinePopup::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_MACHINE_LIST);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
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_MACHINE_LIST);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -2828,20 +2832,23 @@ void SelectMachineDialog::update_user_machine_list()
|
||||
{
|
||||
NetworkAgent* m_agent = wxGetApp().getAgent();
|
||||
if (m_agent && m_agent->is_user_login()) {
|
||||
boost::thread get_print_info_thread = Slic3r::create_thread([&] {
|
||||
boost::thread get_print_info_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_MACHINE_LIST);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
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_MACHINE_LIST);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
wxCommandEvent event(EVT_UPDATE_USER_MACHINE_LIST);
|
||||
|
||||
Reference in New Issue
Block a user