wxTreeCtrl and multithreading - need help ASAP Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
rickg22
In need of some credit
In need of some credit
Posts: 5
Joined: Fri May 27, 2005 10:08 pm

wxTreeCtrl and multithreading - need help ASAP

Post by rickg22 » Sat Dec 31, 2005 8:22 am

Hi, I'm having a serious problem I need help with.

I'm part of the Code::Blocks IDE development team, and my current problem is the class browser, after saving a file it freezes the GUI for 2 or 3 seconds and it's very annoying. The problem is, I don't know how to fix it.

Here's what happens:
After saving a file, the parser updates the class browser's wxTreeCtrl (adding and sorting items), but it's done in the main thread. Due to the amount of information processed (>10,000 items in the tree for large projects, >50,000 with global includes), it takes VERY LONG.

(And using wxApp::Yield is out of the question, it's caused us many headaches before).

My question is: How can I update a GUI object from a thread? My idea was creating a temporary invisible wxTreeCtrl, but I'm not sure how this could be accomplished.

Any help?

chris
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri Oct 08, 2004 2:05 pm
Location: Europe

Post by chris » Sat Dec 31, 2005 12:41 pm

Hi rickg22,

That's generally a tricky situation. Did you have a look at

Code: Select all

wxMutexGuiEnter()
and

Code: Select all

wxMutexGuiLeave()
?
From what I gather, people experienced varied results with them. Last time I used them was somewhere in the early 2.5 branch and it didn't quite work like wanted, but it still might help.

HTH, Chris

P.S.: Good work with C::B, I'm using it myself :wink:

edit and PPS:

You may also experiment with Freeze() and Thaw().
this->signature=NULL;

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Sat Dec 31, 2005 2:39 pm

I strongly advice to stay off the GUI when you are in a seperate thread. This really can cause weird unpredictable behaviour.

What I would do, is update a tree hiararchy in the thread that is responsible for the classes and scanning (I do not know how that is done in C::B) once you are done with gathering info, send the tree in total to the main GUI thread by a messaging synchronisation.

This way the main GUI can update the whole control in one go, and I think Freeze / Thaw can help you with postponing the paint events.

A tree class structure is easily made, as you only need 3-4 classes, and an array definition that points to the base class.

Code: Select all

class treebase
{
// basic functions and info for the name, count etc
};

class treeitem: public treebase
{
// functions for the children that are not recursive
};

class treenode: public treebase
{
// functions for the nodes
private:
  vector<treebase *> m_items;
}

class treeroot: public treenode
{
    // special functions to populate 
}
Returning a complete structure for the GUI component to be updated might give you a speed gain.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

rickg22
In need of some credit
In need of some credit
Posts: 5
Joined: Fri May 27, 2005 10:08 pm

Thanks!

Post by rickg22 » Sat Dec 31, 2005 8:46 pm

I decided to use a structure parallel to the wxTreeCtrl, and update it in a thread. Wish me luck! :)

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Sun Jan 01, 2006 10:44 am

good luck! and happy new year!

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Post Reply