[Gtk-sharp-list] ProgressBar connected to process
Christian Hoff
christian_hoff at gmx.net
Sun May 3 03:32:02 EDT 2009
glacialfury wrote:
> Hi,
>
> I'm experimenting with small programs to learn my way around GTK programming
> with C#/mono. In this case, I have a GUI with three elements: a Button, a
> TextView, and a ProgressBar. Pressing the button runs an external process
> ("ping -c 4 localhost") and displays the output in the textview. This works
> perfectly.
>
> I next attempted to "tie" this in with a progress bar, because there is no
> indicator that it is pinging until it finishes the command and posts the
> output. I have been unable to find any useful tutorials or examples for
> this kind of work. So ...
>
> 1) Is it possible to tie a progress bar to a process? I.e., it starts to
> pulse when the process starts, and ceases to pulse when the process
> finishes?
> ..... while (Process is running) { ProgressBar.pulse(); }
>
I think .net has the possibility to execute a process and wait until it
is terminated. Add a GLib.Timeout(similar to a timer, but the method
will be called from the Gtk+ main loop) before you execute the process.
The method associated with the Timeout should call the Pulse method.
After the process has finished running, you can remove the timeout.
> 2) If I were to then build two commands (and two progress bars) in to the
> program, would they have to be run in separate threads if I wanted them to
> be processed at the same time?
>
Yes, that would probably be the easiest solution. Remeber that only the
Gtk+ thread can access the GUI, see
http://www.mono-project.com/Responsive_Applications.
More information about the Gtk-sharp-list
mailing list