Skip to content
Advertisement

Is there some kind of equivalent to .NET’s BackgroundWorker in Vala?

I’m trying to learn Vala so I’m making a small GUI application. My main language before has been C# so things are going pretty well.

However, I’ve hit the wall now. I need to connect to an external network server (using GIO) which doesn’t answer my client immediately. This makes the GUI freeze up while the program is connecting and doing its thing.

In C# I would probably use a BackgroundWorker in this case. I can’t seem to find anything like it for Vala though.

Basically, I have a MainWindow.vala where I have hooked up a signal for clicking a certain button to a method that is creating a new instance of ProcessingDialog.vala. This shows a dialog over the MainWindow that I want the user to see while the program is doing the work (connecting to the server, communicating).

What are my alternatives to make this scenario work?

Advertisement

Answer

GIO offers async methods, see an async client for example: https://live.gnome.org/Vala/GIONetworkingSample

If you are not aware of async methods in Vala, try looking at the tutorial: https://live.gnome.org/Vala/Tutorial#Asynchronous_Methods

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement