Answer the question
In order to leave comments, you need to log in
Why is another thread blocking the main form?
There is a procedure that fills the tree. Let's say
private void FillingTree()
{
for (int i=0; i<1000;i++)
{
TreeViewItem NewItem=new TreeViewItem();
NewItem.Header=i.ToString();
TreeView1.Dispatcher.Invoke( () =>
{
TreeView1.Items.Add(NewItem);
});
for (int j=0;j<1000;j++)
{
TreeViewItem NewSubItem=new TreeViewItem();
NewSubItem.Header=i.ToString() + "_" + j.ToString();
TreeView1.Dispatcher.Invoke( () =>
{
NewItem.Items.Add(NewSubItem);
});
}
}
}
private void FillTreeAsync()
{
Thread th = new Thread(new ThreadStart(FillingTree));
th.Start();
}
Answer the question
In order to leave comments, you need to log in
TreeView1.Dispatcher.Invoke causes a block, during the execution of Items.Add, in order not to freeze the form, you can try to create a separate treeview in memory and fill it without Dispatcher.Invoke, and at the end, when the work is completed, transfer nodes to it using Dispatcher.Invoke.
But in this case, until the processing is completed, the treeview will be empty
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question