[Gtk-sharp-list] Gui update via thread
JimD
Jim at keeliegirl.dyndns.org
Wed Jun 7 11:35:21 EDT 2006
Hello group,
I am new to Gtk+/Gtk# coming from MS Windows with C# and .Net. I have a
simple app that I am porting from C#/.Net to Mono/Gtk# and have a
question about the best way to update the Gui from a thread.
I just read http://monodevelop.com/Thread_Management which was very
helpful. Winforms have the same requirement that properties/methods be
called from the owner thread.
Here is an example of what I want to do. All the GUI code is contained
in MainWindow. There is another class named Downloader that I want to
run its one and only method, Downloader.GetShowsMP3s, from a thread.
The main method currently connects with a username/password to the Coast
to Coast AM's site and downloads the last shows mp3 files. The method
Downloader.GetShowsMP3s() just has a tight loop to download the mp3
files (4 -5 files) and every N loops I want to check if a custom
property named Cancel of MainWindow has been set to true. If so the
download stops. I also want to update a custom property named Progress
of MainWindow to update the GUI's progressbar.
>From experience, what is the best way to do this in GTK#?
The way I was doing it in the Windows.Forms version of the app was just
to call Application.DoEvents(); every N loop. That is really ugly and
makes the GUI response jerky. For example, clicking on the Cancel
button, the button would not actually "click" for 1-2 seconds.
>From a Mono/Gtk# perspective, which would be the best approach? I was
looking at RunOnMainThread() from here:
http://eric.extremeboredom.net/2004/12/25/113/
The main goal is to have the Cancel button be responsive. I want to
disable all the widgets on MainWindow except for the Cancel button. I
don't mind if the the progress bar is updated every 1-2 seconds and it
is OK if after clicking Cancel it takes about 1-2 second to actually
cancel. I just don't want an unresponsive GUI. I hate that. For
example, I can't stand the Linux version of RealPlayer. If I hide the
RealPlayer window and show it again, it takes a good 5-10 seconds for
the window to be redrawn. If I click stop in the RealPlayer window, it
takes a good 5-10 seconds for the player to actually stop. Grrrr.
Thanks,
Jim
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
You roll an 18 in Dex and see if you
don't end up with a girlfriend
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
JimD
Central FL, USA, Earth, Sol
More information about the Gtk-sharp-list
mailing list