[Mono-list] ThradNotify - (<unknown>:14842): GLib-WARNING **: poll(2) failed due to: Invalid argument.

Moritz Angermann moritz.angermann@gmx.net
Sun, 21 Mar 2004 11:49:46 +0100


--=-JU5Jk9U4i37AkiCDlV0v
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hmm I did some testing with 
ThreadNotify:
And it seems there is some hole or so.

I've attached a small sample application wich ( i hope ) shows this.
For me it stops updating the Statusbar at 780.
Or at 501 when I outcomment the *Console.Out.WriteLine( ... )*.
Than after some time ( the Thread still runs ), I get:

(<unknown>:14842): GLib-WARNING **: poll(2) failed due to: Invalid
argument.

I don't know if this has been fixed already - I'm using Mono 0.30.1
and Gtk# 0.17

:: ResourceFile: tnt.glade
:: References: glade-sharp.dll, gtk-sharp.dll

kindest Regards,
 -mo
-- 
----------------  contact info  ----------------
Moritz Angermann       	moritz.angermann@gmx.net
Liquid:Mint            	www.liquidmint.org
Mobile                 	+49 (0) 160 9197 5880
Home                   	+49 (0) 4322 75 12 66

--=-JU5Jk9U4i37AkiCDlV0v
Content-Disposition: attachment; filename=tnt.glade
Content-Type: text/xml; name=tnt.glade; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="win">
  <property name="visible">True</property>
  <property name="title" translatable="yes">ThreadNotifyTest</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <signal name="delete_event" handler="on_win_delete_event" last_modification_time="Sun, 21 Mar 2004 10:28:04 GMT"/>

  <child>
    <widget class="GtkVBox" id="vbox1">
      <property name="width_request">120</property>
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

      <child>
	<widget class="GtkButton" id="btnGo">
	  <property name="visible">True</property>
	  <property name="can_focus">True</property>
	  <property name="label" translatable="yes">Start</property>
	  <property name="use_underline">True</property>
	  <property name="relief">GTK_RELIEF_NORMAL</property>
	  <signal name="clicked" handler="on_btnGo_clicked" last_modification_time="Sun, 21 Mar 2004 10:05:19 GMT"/>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>

      <child>
	<widget class="GtkStatusbar" id="sb">
	  <property name="visible">True</property>
	  <property name="has_resize_grip">False</property>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>

--=-JU5Jk9U4i37AkiCDlV0v
Content-Disposition: attachment; filename=Main.cs
Content-Type: text/x-csharp; name=Main.cs; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

// created on 03/21/2004 at 11:04
using System;
using System.Collections;
using System.Threading;

using Glade;
using Gtk;

namespace myTests{
	// argumentedThreadNotify
	// -- littel bit modified ThreadNotify to take arguments
	//    and Queue them to get the correctly ordered Output. 
	class argumentedThreadNotify{
		Statusbar sb = null;
		Queue sbMsgQueue = new Queue( );
		
		public argumentedThreadNotify( ref Statusbar s )
		{
			this.sb = s;
		}
		
		// Statusbar Pair...
		public void state( string msg )
		{
			lock( this.sbMsgQueue )
				this.sbMsgQueue.Enqueue( msg );
			new ThreadNotify(
				new ReadyEvent(
					this.updateStatusbar
				)
			).WakeupMain( );
		}
		void updateStatusbar( )
		{
			lock( this.sbMsgQueue )
				while( this.sbMsgQueue.Count > 0 )
				{
					this.sb.Pop( 1 );
					this.sb.Push( 1, (string) this.sbMsgQueue.Dequeue( ) );
				}
		}
	}
	// Thready... Go! Go! Go! --- nothing new here!
	class argumentedThread{
		int sleep = 0;
		int cycles = 0;
		argumentedThreadNotify atv = null;
		public argumentedThread( ref argumentedThreadNotify a, int s, int c )
		{
			this.atv = a;
			this.sleep = s;
			this.cycles = c;
		}
		public void Run( )
		{
			for( int i = 0; i < this.cycles; i++ )
			{
				this.atv.state(  i.ToString( ) + "/" + this.cycles );
				Console.Out.WriteLine( i.ToString( ) + "/" + this.cycles );
				Thread.Sleep( this.sleep );
			}
		}
	}
	// not that Interesting -- application init, open Glade, call Thread on btnClick, Application.Quit.
	class gui{
		[Glade.Widget] Statusbar sb;
		argumentedThreadNotify atv = null;
		Thread runner = null;
		public gui( )
		{
			Application.Init( );
			Glade.XML gxml = new Glade.XML( null, "tnt.glade", "win", null );
			gxml.Autoconnect( this );
			Application.Run( );
		}
		void on_btnGo_clicked( object o, EventArgs args )
		{
			atv = new argumentedThreadNotify( ref sb );
			runner = new Thread(
				new ThreadStart(
					new argumentedThread(
						ref atv,	// argumentedThreadNotify
						10,		// ThreadSleep
						2000 	// Cycles
					).Run
				)
			);
			runner.Start( );
		}
		void on_win_delete_event( object o, EventArgs args )
		{
			runner.Abort( );
			Application.Quit( );
		}
	}
	// Main -- do nothing, but open a new gui!
	class ThreadNotifyTest{
		public static void Main( string[] args )
		{
			new gui( );
		}
	}
}
--=-JU5Jk9U4i37AkiCDlV0v--