[Gtk-sharp-list] Liststore not appending values correctly sometimes

Nil Gradisnik ghaefbgtk at gmail.com
Wed Mar 21 17:55:16 EDT 2007


I need your opinion on this one. I'm running a Thread which starts this
function named PopulateTreevew() and in there this is what happens:

//populate treeview
public void PopulateTreeviewThreadRoutine()
{
        Gtk.Application.Invoke (delegate {
                liststore.Clear();
        });

        for (int i = 0; i < 10; i++) {  
                
                Console.WriteLine (i); //THIS one works
                Gtk.Application.Invoke (delegate {
                        Console.WriteLine (i); //THIS one sometimes
works
                        liststore.AppendValues (i);
                });
        }

        Gtk.Application.Invoke (delegate {
                Treeview1.Model = liststore;
        });
}

My main problem is that I sometimes get all the same(the last) contents
of my variable i to my Treeview, using liststore.AppendValues... I
tested this values with Console.WriteLine.
As you can see I'm using Gtk.Application.Invoke, because I'm running a
Thread outside the main GTK thread.

So basically I narrowed it down to this, that if I print out those
numbers before the Gtk.Application.Invoke, it always prints
out OK, the numbers(i) are 0,1,2,3,4,5,6...9. But If I print them out
inside Gtk.Application.Invoke I sometimes(randomly) get just all 9s !
That is 9,9,9,9,9.......9.

Why is that ? What could cause this problem, I don't understand.
It looks like a bug in Gtk.Application.Invoke or something.

Can I use something else than Gtk.Application.Invoke, so that I get out
the correct array?
Because it looks like the Gtk.Application.Invoke messes up things
randomly.


Please advise

Thanks


Nil Gradisnik




More information about the Gtk-sharp-list mailing list