[Gtk-sharp-list] Gui update via thread

Brian Bell ve7qer at gmail.com
Wed Jun 7 17:57:24 EDT 2006


I have to admit to having some major confusion on this issue. All the
documentation I've been able to find is completely conflicting.

I have a slight twist I'd like to put on this question.

Just for fun/learning I am writing a little Gaim-like IM client in GTK#

I'll post a abbreviated version of what I'd like to do and see if
someone can point me to a good reference doc at least ;)

I know it has to do with invoke/delegates, but not sure how to get it
to run from another class

Any help/pointers/references are appreciated. Thx!

//------------------------------------------------
//main.cs
using System;
using Gtk;
using GtkSharp;
using System.Threading;
namespace chat
{
	class MainClass
	{
                 private static Window win = null;
                 private static Gtk.Entry output;
                 private static Gtk.Entry input;
                 private static Gtk.Button go_button;

                 private static irc_thread irc;

                 public static void Main (string[] args)
	     		{
	          		  Application.Init ();
	          		  win = new Window ("Chat");
                      VBox main_vBox1 = new VBox (false, 3);

                      incoming = new Gtk.Entry(); // show text coming from irc
                      main_vBox.PackStart(incoming, true, true, 0);

                      output = new Gtk.Entry(); // text to be sent to IRC
                      output.Activated += new EventHandler(go_button_click);
                      main_vBox1.PackStart(output, true,true,1);

                      go_button = new Gtk.Button("Go");
                      go_button.Clicked += new EventHandler(go_button_click);
                      main_vBox1.PackStart(go_button, true,true,2);

                      irc_thread irc = new irc_thread();
					  Thread t = new Thread (irc.go);//the goal is to actually be
able to spawn more than one thread...but for simplicity sake
					 //missing something here?
    				  t.Start();
    				  win.Add (main_vBox1);
					  win.ShowAll ();
		  			  Application.Run ();
				}
				
				public static void go_button_click(object sender, EventArgs args)
				{
					// post output.Text to irc.message;
				}
				public static void update_incoming_entry(string text_from_irc)
				{
					// how do I retrieve a value from my irc_thread class?
					incoming.Text = text_from_irc;
				}
		}//class MainClass
	}//namespace chat
	// end main.cs
//------------------------------------------------
	//irc_thread.cs
	using System;
	using System.Threading;
	using irclib;
	
	namespace chat
	{
		class irc_thread
		{
			public void go()
        	{
        		// this will contain the various socket functions and it's
own thread/loop ( smartirc4net )
        	}
        	
        	public ON_got_msg_from_irc
        	{
        		// how do I send a string to the main thread?
        	}
        	
        	public static void message()
        	{
        		// how do I get something from the main thread (output.Text)?
        	
        	}
        } // class irc_thread
   } //namespace chat
   //end irc_thread.cs
   //------------------------------------------------


More information about the Gtk-sharp-list mailing list