When I useProgramAdd 0.1 million nodes to the Treeview;
No matter you use. begininvoke or other multi-threaded addition methods, the following results cannot be achieved:
In this way, the Treeview can respond to a series of operations-double-click and expand .. And so on;
Is there a way to solve this problem? Is this a natural defect in the Treeview space?
I once saw someone using MFC to implement the function of adding nodes while performing a response operation!
Which one can tell me the answer?
Add Method 1:
Treenode tn;
For (INT I = 0; I <100000; I ++)
{
Tn = new treenode (I. tostring ());
This. treeview1.nodes [0]. nodes. Add (TN );
}
No doubt, the CPU usage is 100%, and the interface cannot respond
Method 2:
Private void form1_doubleclick (Object sender, system. eventargs E)
{
This. treeview1.begininvoke (New treeinvoke (this. updatetreeview ));
}
Private void updatetreeview ()
{
System. datetime dt = datetime. now;
Treenode tn;
// This. treeview1.beginupdate ();
For (INT I = 0; I <100000; I ++)
{
Tn = new treenode (I. tostring ());
This. treeview1.nodes [0]. nodes. Add (TN );
If (I % 100 = 0)
{
System. Threading. thread. Sleep (100 );
}
}
// This. treeview1.endupdate ();
System. timespan Ts = datetime. Now-dT;
MessageBox. Show (TS. tostring ());
}
CPU utilization is not high, but the interface cannot respond
Method 3:
Private void form1_doubleclick (Object sender, system. eventargs E)
{
System. datetime dt = datetime. now;
For (INT I = 0; I <10000; I ++)
{
This. treeview1.begininvoke (New treeinvoke (this. updatetreeview ));
System. Threading. thread. Sleep (10000 );
}
System. timespan Ts = datetime. Now-dT;
MessageBox. Show (TS. tostring ());
}
Private void updatetreeview ()
{
Treenode tn;
// This. treeview1.beginupdate ();
For (INT I = 0; I <10; I ++)
{
Tn = new treenode (I. tostring ());
This. treeview1.nodes [0]. nodes. Add (TN );
}
// This. treeview1.endupdate ();
}
Result approximation method 2;
Is there any way to use Treeview to achieve my goal without changing the content organization method (non-hierarchical display?