Re: About Treeview update with thread



hi, muppet

many thanks for your reply and your suggestions.

- Remember to grab and release the gdk lock around the gui accesses from the other thread, or

  Do you mean use Gtk2::Gdk::Threads->enter and Gtk2::Gdk::Threads->leave when i update the treeview?   I change my code as below:
 

       sub oneCaseComplete {
 
                Gtk2::Gdk::Threads->enter;
 
                my ($this, $tid) = @_;
                my $iter = $this->{caseiters}->{$tid};
                my $case = $model->get_value($iter, COLUMN_CASEOBJ);
                my $model = $this->{widgets}->{treeview}->get_model;
                # update the TreeView
                $model->set($iter,COLUMN_STATUS, $case->getRunResult);
                $model->set($iter,COLUMN_TIME, $case->getUsedTime);    
 
                Gtk2::Gdk::Threads->leave; 
 
          }
 
I have run the changed code, but it is no better, the same problem aslo exist.  Is there any  thing missed when i grab and release the gdk lock use Gtk2::Gdk::Threads->enter/leave.
 

- Instead of immediately modifying the treemodel in your background thread, install a single-shot idle that will do it.  This effectively defers the work to the main thread so that only one thread touches the ui.
 
For this suggestion, do you mean I use a Gtk2::Idle->add(sub {  }) in the main thread, and in this function to update the Treeview. 
But how the main thread to know which row should be updated?
or to loop each row to update the whole treeview, but there exist efficiency issues.
 
 
Do my understanding correct?  Can you give a bit more detailed explanations
Thanks again for your suggestion
 
Ruibot



2009/5/9 muppet <scott asofyet org>

On May 8, 2009, at 10:51 PM, 唐瑞博 wrote:

hi,
In my project, The GUI have a treeview and a 'Run' Button,Treestore may have thourands of datas.

When i click the 'Run' button, the logci will process the treestore datas one by one(this is a long time procedure), when one data process complete, i need to update the Treeview immediately.

In order to avoid the GUI lag, I use a thread to do the backend processing. The problem is when the thread to update the Treeview, the logic will fail.


- Remember to grab and release the gdk lock around the gui accesses from the other thread, or

- Instead of immediately modifying the treemodel in your background thread, install a single-shot idle that will do it.  This effectively defers the work to the main thread so that only one thread touches the ui.




--
Sallah!  I said no camels!  That's five camels!  Can't you count?
 -- Indiana Jones




--
Best Regards

Tang Ruibo(唐瑞博)
===============================
Beijing University of Posts and Telecommunications

E-mail:  ruibotang gmail com
T e l :    (86)10-62283926


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]