On Fri, 26 Jan 2018 11:14:36 +0700 "Lucky B.C" <lblack...@gmail.com> wrote: > Well, in the case, I will tell something about me, first I've never > used the GtkApplication just main window maybe sub windows (dialogs) > too, and my programs did not do as what you are trying to do. Second > I'm a C programmer, in my opinion, you should redesign your app > because sometimes we must do that to gain our main target not about > GUI which we only need for rendering/displaying to the user. Nothing > is perfect! If we don't want the user see the private data or > something else, we just don't show it by doing in another thread. > Yes, the main loop of GTK always runs after we called gtk_main (), > but we can create another thread before gtk_init () is called and run > it anytime we need by gdk_threads_enter and gdk_threads_leave, for > more detail see GThreads > <https://developer.gnome.org/glib/stable/glib-Threads.html#g-thread-new> > and IDLES > <https://developer.gnome.org/gdk2/stable/gdk2-Threads.html>. Finally > just reload/refresh our new data/thing again to the user or show a > message dialog says somthing else, for example "Your data changed!". > I wonder is there some programs which have the same what you are > trying to do? If there's one or more, please send me the link, I > really want to test them.
gdk_threads_enter and gdk_threads_leave are absolutely not the way to do it. They are deprecated in GTK+3 and will be removed in GTK+4. Furthermore they only work with the X backend (not with windows or wayland) and are horribly error-prone. The correct way for a worker thread to pass back a result to the glib main loop, or to execute code in that loop, is for it to post an event using g_idle_add() and cognates. The glib main loop is thread safe. gdk_threads_add_idle is only necessary if your code interfaces with ancient third-party library code which uses gdk_threads_enter and gdk_threads_leave. The best thing to do with such ancient libraries is not to use them. Chris _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list