[Gtk-sharp-list] Thread-safe GUI update

Leon Stringer leon.stringer at ntlworld.com
Mon Mar 26 15:32:28 EDT 2007


Michael Hutchinson wrote:
> Remember I mentioned Gtk.Application.Invoke (object sender,
> System.EventArgs args, System.EventHandler d) could be a solution?
> 
> while (Messages.Count > 0) {
>    msg = (Message) Messages.Dequeue();
>    send(msg);
>    Gtk.Application.Invoke(this, new MsgEventArgs(msg), new delegate
>            (object sender, MsgEventArgs args) {
>                treeStore.AppendAvalues(args.Message.To, args.Message.Text);
>            }
>    );
>    Thread.Sleep(0);
> }
> 
> class MsgEventArgs : EventArgs
> {
>    public Message Message;
>    public MsgEventArgs (Message msg)
>    {
>        Message = msg;
>    }
> }
> 
> EventArgs-derived classes are the standard C# pattern for arguments to
> event handlers. Of course you can add convenience constructors, use
> properties for accessors etc.
> 

Yes I did remember, but I couldn't find any documentation or examples 
describing how to do this. Thanks for posting this example, I've got it 
working and that seems to have done the trick. I wouldn't have worked it 
out without yours and William's help so thanks to you both...

For anybody else trying this solution, there's no "new" before 
"delegate" i.e.:

     Gtk.Application.Invoke(this, new MsgEventArgs(msg ), delegate
                 (object sender, MsgEventArgs args) {


More information about the Gtk-sharp-list mailing list