[Gtk-sharp-list] Timers & GLib.Timeout, passing arguments?

Matt Williams matt.williams@OrbisUK.com
04 Jun 2003 15:47:44 +0100


I'm having some trouble working out how to implement timers correctly. 
I'm quite new to GTK#/C#, so I may have missed something fundamental.

What I have at the moment is a GUI that opens a socket to a server and
based on messages it receives draws various things to a Gnome.Canvas. 
This all works ok so far.

The problem is now that I need have some kind of animation on the
canvas, my plan was to do this with timers, however I've run into some

I've tried various timers, System.Timers, System.Threading, etc. but
have eventually settled on GLib.Timeout.

My problem is that I can't figure out the correct way of passing
arguments through the event loop.  The code is pretty small..

I add a timeout event in the following way:

public class SomeClass

    public void ProcessMessage ()
        GLib.Timeout.Add(1000, new GLib.TimeoutHandler(DoSomin));

    public bool DoSomin ()
        // do something to the canvas

If the handler is not static then I have the problem that I'm not sure
how to handle the case when the object and thus the instance of the
handler is destroyed.

If the handler *is* static then this overcomes the previous problem, but
I can't pass any data to the handler, for example which object on the
display to update.

Thanks in advance


Matt Williams