[Gtk-sharp-list] Gtk# threading problem?

Pablo Baena pbaena@uol.com.ar
09 Oct 2002 15:46:00 +0000


--=-k0H4Je8OIPwedMMtoVC7
Content-Type: multipart/alternative; boundary="=-U/pnuV2dzJXbLSQeIM2e"


--=-U/pnuV2dzJXbLSQeIM2e
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello! I am a Gtk#/C#/OOP newbie, and I am making my first steps into
Gnome programming. So far, it all seems so clean and easy (apart from
problems bootstrapping mono :).

Well, it seems I got my first blockage though. I tried to isolate the
problem, and did a test case, so you can see the problem. To be certain,
maybe it is a programming error of mine, but I couldn't tell because I
am so new to all this.

What I am trying to do is to run a external program and to see the
output stream in a text view, all this with threads so my program
doesn't freeze. The problem is that the output stream doesn't show until
I click the textview, and so and so until the external prog stops
sending output.

What I found out is that getting all the gnome stuff from my program
out, it does what it is meant. I mean, commenting all the gnome stuff
from my program.

Can you people look at this (please try not to horrify about my OOP
programming skills :) and help me?
Thank you!!
Pablo


________________________________________________________________________


<Tetsuo> la vida es muy ironica vio?
<Ranma> sip la verdad que se nos esta cagando de risa!
<Ranma> y la voy a cagar a pi=F1as

--=-U/pnuV2dzJXbLSQeIM2e
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/1.0.4">
</HEAD>
<BODY>
Hello! I am a Gtk#/C#/OOP newbie, and I am making my first steps into Gnome programming. So far, it all seems so clean and easy (apart from problems bootstrapping mono :).
<BR>

<BR>
Well, it seems I got my first blockage though. I tried to isolate the problem, and did a test case, so you can see the problem. To be certain, maybe it is a programming error of mine, but I couldn't tell because I am so new to all this.
<BR>

<BR>
What I am trying to do is to run a external program and to see the output stream in a text view, all this with threads so my program doesn't freeze. The problem is that the output stream doesn't show until I click the textview, and so and so until the external prog stops sending output.
<BR>

<BR>
What I found out is that getting all the gnome stuff from my program out, it does what it is meant. I mean, commenting all the gnome stuff from my program.
<BR>

<BR>
Can you people look at this (please try not to horrify about my OOP programming skills :) and help me?
<BR>
Thank you!!
<BR>
Pablo
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>

<BR>

<HR>

<BR>

<PRE>&lt;Tetsuo&gt; la vida es muy ironica vio?
&lt;Ranma&gt; sip la verdad que se nos esta cagando de risa!
&lt;Ranma&gt; y la voy a cagar a pi&#241;as</PRE>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

--=-U/pnuV2dzJXbLSQeIM2e--

--=-k0H4Je8OIPwedMMtoVC7
Content-Disposition: attachment; filename=test.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=test.cs; charset=ISO-8859-1

namespace test
{
	using Gtk;
	using Gdk;
	using GtkSharp;
	using System;
	using System.IO;
	using System.Drawing;
	using System.Runtime.InteropServices;
	using System.Diagnostics;
	using System.Threading;
	using Gnome;
=09
	class mainone
	{
		public static void Main(string[] args)
		{
			test_threads tt =3D new test_threads(args);
		}
	}

	class test_threads
	{
		public Gtk.Window window =3D null;
		public TextView textview =3D null;

		public test_threads(string[] args)
		{

			Program kit =3D new Program ("gnomencoder", "0.0.1", Modules.UI,
				args);
			window =3D new Gtk.Window ("Test");
			window.SetDefaultSize (250, 200);=09
			VBox box1 =3D new VBox (false, 0);
			window.Add (box1);
			Button btn =3D new Button ("Click Me");
			btn.Clicked +=3D new EventHandler (btn_click);
			window.DeleteEvent +=3D new DeleteEventHandler (Window_Delete);
			box1.PackStart (btn, true, true, 4);
			Frame statusframe =3D new Frame("Status");
			ScrolledWindow sw =3D new ScrolledWindow ();
			textview =3D new TextView();
			textview.Editable =3D false;
			textview.WrapMode =3D Gtk.WrapMode.Char;
			textview.CursorVisible =3D false;
			sw.Add(textview);
			statusframe.Add(sw);
			box1.PackStart (statusframe, true, true, 4);
			window.ShowAll ();
			kit.Run();
		}=09

		void btn_click (object obj, EventArgs args)
		{
			jobs job =3D new jobs(textview);

			Console.WriteLine ("Button Clicked");

		}

		void Window_Delete (object obj, DeleteEventArgs args)
		{
			Application.Quit ();
			args.RetVal =3D true;
		}
	}

	public class jobs
	{
		TextView text =3D null;
		public jobs(TextView textar)
		{
	        Thread thr =3D new Thread (new ThreadStart (ThreadFunc));
            thr.Start ();
            //thr.Join ();
			text =3D textar;
		}
		public void ThreadFunc()
		{
			ProcessStartInfo psi =3D new ProcessStartInfo();
			psi.FileName=3D"ls";
			psi.Arguments=3D"/usr/share/doc";
			psi.WorkingDirectory=3D"/tmp/";
			psi.RedirectStandardOutput=3Dtrue;
			Process p =3D Process.Start(psi);
			//p.WaitForExit();		=09
			string output;
			TextBuffer buff =3D text.Buffer;
			while ((output =3D p.StandardOutput.ReadLine())!=3Dnull) {
				buff.InsertAtCursor(output+'\n', -1);
			}
		}
	}
}
--=-k0H4Je8OIPwedMMtoVC7--