[Gtk-sharp-list] GTK# app "hanging"

Jonathan Pryor jonpryor@vt.edu
Tue, 22 Feb 2005 17:58:57 -0500


On Tue, 2005-02-22 at 23:16 +0100, Raúl Moratalla wrote:
> Thanks for your info Jon but I have the following question.
> I added a line like this in my program:
> 
> Gtk.Timeout.Add(0,delegate{m_Log(this,importance,strMsg);});
> 
> If I compile my program I get the following error:
> Not all code paths return a value in anonymous method of type 
> `Mono.CSharp.AnonymousMethod'(CS1643)
> 
> What am I doing wrong?

Let's follow the types...  Gtk.Timeout.Add is declared as:

	public delegate bool Gtk.Function ();

	public class Gtk.Timeout {
		public static uint Add (uint interval, Function function);
	}

Basically, the delegate passed to Gtk.Timeout.Add is expected to return
a `bool'.  Your delegate doesn't, resulting in the compiler error.

To fix this, return a value from your anonymous delegate (I return
`false' because the return value specifies whether or not the delegate
should be called again, and I assume you don't want it called again):

	Gtk.Timeout.Add (0, delegate {
		m_Log (this, importance, strMsg);
		return false;
	});

 - Jon