Search code examples
gtkvala

Vala, GTK :How do I perform UI operations from a different thread?


I have a server listening for messages on a port running in a different thread. Now once it receives a message I need it to be displayed in a textbox.

  1. Is there method like runOnUiThread() (which is in android) or equivalent in Vala, GTK?

  2. Or else what are the alternatives?


Solution

  • Use GLib.Idle.add to schedule something in the event dispatch thread:

    Idle.add(() => {
      textbox.Entry = "foo";
      return Source.REMOVE;
    });