C
Chris
Hi everyone-
So I have this treeview control that I'm populating from a dataset.
Problem is, there are 10 tables in the dataset (I didn't set the
database up, for the record). So I'm having to make 10 foreach loops
to get all the 'branches' in the treeview. As you might expect, this
is super slow. So I was thinking I could thread it. Build the first
half of the treeview in one thread, build the second half in the other
thread, and put the two together. Now in the processes that my thread
executes, I'm adding my treenodes. And when I add breakpoints and
check, they're allegedly there. But when the page renders, there's no
treeview displayed.
public void TestThread()
{
TreeView tvTemp = new TreeView();
Thread[] thTempThread = new Thread[2];
thTempThread[0] = new Thread(new ThreadStart(BuildListPart1));
thTempThread[1] = new Thread(new ThreadStart(BuildListPart2));
thTempThread[0].Start();
thTempThread[1].Start();
}
public void BuildListPart1()
{
foreach (DataRow drChapter in
Books.dsBookTOC().Tables[2].Rows) //Get all book chapters
{
foreach (DataRow drChapNum in
drChapter.GetChildRows("ChapterTable")) //Get all chapter numbers
pertaining to this book
{
TreeNode trChapter = new
TreeNode(drChapter[5].ToString(), drChapter[3].ToString());
tvChapterList.Nodes.Add(trChapter);
foreach (DataRow drSection in
drChapNum.GetChildRows("Section")) //Get all Sections pertaining to
this chapter
{
TreeNode trSection = new
TreeNode(drSection[3].ToString() + " " + drSection[4].ToString(),
drSection[1].ToString());
trChapter.ChildNodes.Add(trSection);
}
}
}
}
And the second function grabs the rest of the list. Do I have to pass
my treeview as a parameterized thread, or something? Any help is
appreciated.
So I have this treeview control that I'm populating from a dataset.
Problem is, there are 10 tables in the dataset (I didn't set the
database up, for the record). So I'm having to make 10 foreach loops
to get all the 'branches' in the treeview. As you might expect, this
is super slow. So I was thinking I could thread it. Build the first
half of the treeview in one thread, build the second half in the other
thread, and put the two together. Now in the processes that my thread
executes, I'm adding my treenodes. And when I add breakpoints and
check, they're allegedly there. But when the page renders, there's no
treeview displayed.
public void TestThread()
{
TreeView tvTemp = new TreeView();
Thread[] thTempThread = new Thread[2];
thTempThread[0] = new Thread(new ThreadStart(BuildListPart1));
thTempThread[1] = new Thread(new ThreadStart(BuildListPart2));
thTempThread[0].Start();
thTempThread[1].Start();
}
public void BuildListPart1()
{
foreach (DataRow drChapter in
Books.dsBookTOC().Tables[2].Rows) //Get all book chapters
{
foreach (DataRow drChapNum in
drChapter.GetChildRows("ChapterTable")) //Get all chapter numbers
pertaining to this book
{
TreeNode trChapter = new
TreeNode(drChapter[5].ToString(), drChapter[3].ToString());
tvChapterList.Nodes.Add(trChapter);
foreach (DataRow drSection in
drChapNum.GetChildRows("Section")) //Get all Sections pertaining to
this chapter
{
TreeNode trSection = new
TreeNode(drSection[3].ToString() + " " + drSection[4].ToString(),
drSection[1].ToString());
trChapter.ChildNodes.Add(trSection);
}
}
}
}
And the second function grabs the rest of the list. Do I have to pass
my treeview as a parameterized thread, or something? Any help is
appreciated.