# GTK4 periodic signal to refresh data display

**URL:** <https://discourse.julialang.org/t/gtk4-periodic-signal-to-refresh-data-display/112997>\
**Category:** Visualization\
**Created:** [April 16, 2024, 8:19am UTC](https://discourse.julialang.org/t/gtk4-periodic-signal-to-refresh-data-display/112997 "2024-04-16T08:19:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yjr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yjr/32/207725_2.png) [@yjr](https://discourse.julialang.org/u/yjr)\
**Post date:** [April 16, 2024, 8:19am UTC](https://discourse.julialang.org/t/gtk4-periodic-signal-to-refresh-data-display/112997/1 "2024-04-16T08:19:30Z")

</div>

Hello, I would like to know the best way to repeatedly update some labels. Currently I use Gtk4.g\_timeout\_add(cb,ms) . cb being a callback retrieving new values and updating corresponding labels.  
But it tends to render everything sluggish, REPL included…  
Although I m not aware how to clean these signal after program closure …  
Help appreciated  
Thanks

---

<div class="post-metadata">

**Author:** ![jwahlstrand](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jwahlstrand](https://discourse.julialang.org/u/jwahlstrand)\
**Post date:** [April 24, 2024, 12:59am UTC](https://discourse.julialang.org/t/gtk4-periodic-signal-to-refresh-data-display/112997/2 "2024-04-24T00:59:50Z")

</div>

How long does your callback take and how often is it being called? The function `g_timeout_add` calls it via the GTK event loop. If the callback takes a long time to return (more than say tens of milliseconds), it will prevent events and draws from being processed as often as needed to keep the UI interactive.

Lengthy computation and IO should be offloaded to a task on another thread. At the end of this other task you can update the label on the UI thread using `g_idle_add`. See [Asynchronous UI · Gtk4.jl](https://juliagtk.github.io/Gtk4.jl/dev/howto/async/).

You can stop the timeout by returning `false` from the callback or by calling `g_source_remove` on the ID returned by `g_timeout_add`: see [docstring for `g_timeout_add`](https://juliagtk.github.io/Gtk4.jl/dev/doc/GLib_reference/#Gtk4.GLib.g_timeout_add).
