From 95a22dd13b879ecb4f3e59d92afa36b937f5c819 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 2 Sep 2005 22:39:17 +0000 Subject: [PATCH] i2005-09-02 Miguel de Icaza * gtk/Application.cs (Invoke): Add new overloads to easily invoke methods on the executing thread. svn path=/trunk/gtk-sharp/; revision=49379 --- ChangeLog | 10 ++++++++++ gtk/Application.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/ChangeLog b/ChangeLog index 4c218ee7b..13d0b2091 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-09-02 Miguel de Icaza + + * gtk/Application.cs (Invoke): Add new overloads to easily invoke + methods on the executing thread. + +2005-09-01 Miguel de Icaza + + * gtk/Application.cs (Invoke): Add sugar to invoke a method on the + main thread. + 2005-09-02 Ben Maurer * sample/NodeViewDemo.cs: take advantage of the stuff below diff --git a/gtk/Application.cs b/gtk/Application.cs index d911e64d5..3787c2073 100755 --- a/gtk/Application.cs +++ b/gtk/Application.cs @@ -141,5 +141,45 @@ namespace Gtk { return new Gdk.Event (gtk_get_current_event ()); } } + + internal class InvokeCB { + EventHandler d; + object sender; + EventArgs args; + + internal InvokeCB (EventHandler d) + { + this.d = d; + args = EventArgs.Empty; + sender = this; + } + + internal InvokeCB (EventHandler d, object sender, EventArgs args) + { + this.d = d; + this.args = args; + this.sender = sender; + } + + internal bool Invoke () + { + d (sender, args); + return false; + } + } + + public static void Invoke (EventHandler d) + { + InvokeCB icb = new InvokeCB (d); + + GLib.Idle.Add (new GLib.IdleHandler (icb.Invoke)); + } + + public static void Invoke (object sender, EventArgs args, EventHandler d) + { + InvokeCB icb = new InvokeCB (d); + + GLib.Idle.Add (new GLib.IdleHandler (icb.Invoke)); + } } }