I assume the error message points to this piece of code? (If not, you should provide us with the exact error message.) You should be able to fix that by moving the
let label_clone = fragile::Fragile::new(label.clone());
into the loop, like this:
if response.body.contains("PING OK") {
let label_clone = fragile::Fragile::new(label.clone());
glib::MainContext::default().invoke(move|| {
label_clone.get().set_text("ping ok");
});
}
The first time invoke is called, label_clone is moved into the closure, so you can't use it anymore in the other iterations. The above code creates a new label_clone every time invoke is called, so each time, a new value is moved into the closure.
I try but if I put into the loop I get this error message:
*mut *mut gtk_sys::_GtkWidgetPrivate cannot be sent between threads safely
--> src/main.rs:291:5
|
291 | thread::spawn(move || {
| ^^^^^^^^^^^^^ *mut *mut gtk_sys::_GtkWidgetPrivate cannot be sent between threads safely
You cannot use gtk from more than one thread at once. If you want to interact with gtk from another thread, you will have to use channels to ask the main thread to do it. The glib crate provides a channel that integrates with gtk rather nicely.