[Gtk-sharp-list] Gtk# 2.10.0 on Windows

Chris Lee chris at lee-gertner.net
Tue Apr 17 19:32:13 EDT 2007


On Tue, 2007-04-17 at 15:36 -0400, Chris Lee wrote:

>       * Rewrite those parts of my app that use Gtk.Application.Invoke
>         (which is possible, but not very easy or fun, as far as I can
>         tell).

I thought about it for a while, and I think that the following code
pretty much does what I need without having to change the way I use
delegates....  So I can avoid gtk-2.10 for now!

public class MyApplication {

	public delegate void Runnable();

	public static List<Runnable> queuedForInvoke;
	private static ThreadNotify notifyForInvoke;
	private static void _Invoke() {
		List<Runnable> cr;
		lock (queuedForInvoke) {
			cr = new List<Runnable>(queuedForInvoke);
			queuedForInvoke.Clear();
		}
		foreach (Runnable r in cr) { r(); }
	}
	public static void Invoke(Runnable runnable) {
		if ( null == queuedForInvoke ) {
			queuedForInvoke = new List<Runnable>();
			notifyForInvoke = new ThreadNotify (new ReadyEvent (_Invoke));
		}
		lock (queuedForInvoke) {
			queuedForInvoke.Add(runnable);
		}
		notifyForInvoke.WakeupMain();
	}
}




More information about the Gtk-sharp-list mailing list