Sadeep Weerasinghe
Sadeep Weerasinghe

Reputation: 1087

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?

Upvotes: 2

Views: 289

Answers (2)

apmasell
apmasell

Reputation: 7153

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

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

Upvotes: 4

Sadeep Weerasinghe
Sadeep Weerasinghe

Reputation: 1087

In contrast to many other Operating Systems, apparently you could perform UI operations from a non UI thread. I could successfully change the text of an Entry from the server thread. Not sure if this is recommended though.

Upvotes: -1

Related Questions