[Gtk-sharp-list] Newbie's TreeView updates *very* slowly

Chris Howie cdhowie at gmail.com
Tue Dec 30 19:45:35 EST 2008


On Tue, Dec 30, 2008 at 7:37 PM, fourthirtysix <fourthirtysix at yahoo.com> wrote:
> I've read over many of the suggestions and links in the replies, thank you to
> everyone, and have added in Threading to keep the GUI responsive. There is
> one weird catch however--
>
> I load about 500,000 records into a huge ArrayList and then run multiple
> searches over that. Each time I iterate over the big list, it generates a
> "hit" and I want to update the ListStore. I do so with an AppendValues,
> however the GUI does not refresh completely.
>
> I can see it "sort of" refresh for some of my hits.. It will put in a few
> values for each row, or add in a zero as placeholders, but it does not
> update the entire screen properly until the hits are mostly in and I
> actually move the mouse cursor into the treeview section of the GUI. It may
> be that I have to hover over an actual Row, but I need to test some more.

Usually this is a symptom of invoking AppendValues on the model from a
different thread than the GTK+ event loop thread.  Make sure that you
are using Application.Invoke each time you touch the model from a
different thread, like this:

Application.Invoke(delegate {
    foreach (object i in something) {
        model.AppendValues(i);
    }
});

You can invert the nesting there (iterate and call Invoke instead of
iterating inside the delegate) if the results come in slowly enough
that doing cross-thread synchronization doesn't slow it down
significantly.  Otherwise doing one cross-thread call and throwing a
whole batch in at once is the way to go.

(Note that Application.Invoke does *not* wait for the delegate to be
executed.  It returns immediately after pushing the delegate on the
event stack, so careful your code doesn't step on itself.)

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers


More information about the Gtk-sharp-list mailing list