[Gtk-sharp-list] ThreadNotify

Pablo Baena pbaena@uol.com.ar
11 Oct 2002 03:12:05 +0000


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

Tried this with gtk-sharp from CVS, doesn't seem to work neither. Am I
doing it correctly? I think those lock statements are unnecesary though.


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 System.Collections;
	using Gnome;
=09
	class mainone
	{
		public static void Main(string[] args)
		{
			test_threads tt =3D new test_threads(args);
		}
	}

	class test_threads
	{
		public Gnome.App window =3D null;
		TextView textview =3D null;
		ThreadNotify tn =3D null;=20
		TextBuffer buff =3D null;
		Queue queue=3Dnull;
					=09
		public test_threads(string[] args)
		{
			tn=3Dnew ThreadNotify(new ReadyEvent(show_status));
			queue=3Dnew Queue();
		=09
			Program kit =3D new Program ("test", "0.0.1", Modules.UI,
				args);
			window =3D new Gnome.App ("test", "Test");
			window.SetDefaultSize (250, 200);=09
			window.DeleteEvent +=3D new DeleteEventHandler (Window_Delete);
		=09
			VBox box1 =3D new VBox (false, 0);

			Button btn =3D new Button ("Click Me");
			btn.Clicked +=3D new EventHandler (btn_click);
			box1.PackStart (btn, true, true, 4);

			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);
			box1.PackStart (sw, true, true, 4);
		=09
			buff =3D textview.Buffer;
			window.Contents=3Dbox1;
			window.ShowAll ();
			kit.Run();
		}=09

		void btn_click (object obj, EventArgs args)
		{
			Thread thr =3D new Thread (new ThreadStart (ThreadFunc));
			thr.Start ();
			Console.WriteLine ("Button Clicked");
		}

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

		public void show_status()
		{
			string tmp =3D null;
			lock (this) {
				tmp =3D (string) queue.Dequeue();
				Console.WriteLine("showing: {0}",tmp);
				buff.InsertAtCursor(tmp+'\n', -1);
			}
			=09
		}

		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);
			string tmp;
			while ((tmp =3D p.StandardOutput.ReadLine())!=3Dnull) {
				lock (this)=20
				{
					Console.WriteLine("sending: "+tmp);
					queue.Enqueue(tmp);
					tn.WakeupMain();
					//show_status();
				}
			}
		}
	}
}



________________________________________________________________________


<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

--=-T4OPClvCrFhKrxyRHV7T
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>
Tried this with gtk-sharp from CVS, doesn't seem to work neither. Am I doing it correctly? I think those lock statements are unnecesary though.
<BR>

<PRE>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 System.Collections;
	using Gnome;
	
	class mainone
	{
		public static void Main(string[] args)
		{
			test_threads tt = new test_threads(args);
		}
	}

	class test_threads
	{
		public Gnome.App window = null;
		TextView textview = null;
		ThreadNotify tn = null; 
		TextBuffer buff = null;
		Queue queue=null;
						
		public test_threads(string[] args)
		{
			tn=new ThreadNotify(new ReadyEvent(show_status));
			queue=new Queue();
			
			Program kit = new Program (&quot;test&quot;, &quot;0.0.1&quot;, Modules.UI,
				args);
			window = new Gnome.App (&quot;test&quot;, &quot;Test&quot;);
			window.SetDefaultSize (250, 200);	
			window.DeleteEvent += new DeleteEventHandler (Window_Delete);
			
			VBox box1 = new VBox (false, 0);

			Button btn = new Button (&quot;Click Me&quot;);
			btn.Clicked += new EventHandler (btn_click);
			box1.PackStart (btn, true, true, 4);

			ScrolledWindow sw = new ScrolledWindow ();
			textview = new TextView();
			textview.Editable = false;
			textview.WrapMode = Gtk.WrapMode.Char;
			textview.CursorVisible = false;
			sw.Add(textview);
			box1.PackStart (sw, true, true, 4);
			
			buff = textview.Buffer;
			window.Contents=box1;
			window.ShowAll ();
			kit.Run();
		}	

		void btn_click (object obj, EventArgs args)
		{
			Thread thr = new Thread (new ThreadStart (ThreadFunc));
			thr.Start ();
			Console.WriteLine (&quot;Button Clicked&quot;);
		}

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

		public void show_status()
		{
			string tmp = null;
			lock (this) {
				tmp = (string) queue.Dequeue();
				Console.WriteLine(&quot;showing: {0}&quot;,tmp);
				buff.InsertAtCursor(tmp+'\n', -1);
			}
				
		}

		public void ThreadFunc()
		{
			ProcessStartInfo psi = new ProcessStartInfo();
			psi.FileName=&quot;ls&quot;;
			psi.Arguments=&quot;/usr/share/doc&quot;;
			psi.WorkingDirectory=&quot;/tmp/&quot;;
			psi.RedirectStandardOutput=true;
			Process p = Process.Start(psi);
			string tmp;
			while ((tmp = p.StandardOutput.ReadLine())!=null) {
				lock (this) 
				{
					Console.WriteLine(&quot;sending: &quot;+tmp);
					queue.Enqueue(tmp);
					tn.WakeupMain();
					//show_status();
				}
			}
		}
	}
}</PRE>
<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>

--=-T4OPClvCrFhKrxyRHV7T--