problem in working with thread
Posted
by Xaver
on Stack Overflow
See other posts from Stack Overflow
or by Xaver
Published on 2010-04-14T10:36:10Z
Indexed on
2010/04/14
10:42 UTC
Read the original article
Hit count: 280
visual-c++
|.NET
Ihave the tree view in which i have file system of logical disk. When user select some files and folders and press button programm evaluate the size of selected files and folders. this function may takes a long time. i decide do thread which will run this function. This function works with array of TreeNode. but then i want to now was it node expaned or not compiler say: "attempt to access control "treeview1" not from the thread, in which it was created." Why it appeared? Next code is show how i create array of Nodes which i send to new thread:
void frmMain::FillSelected(TreeNode^ a, array<TreeNode^>^ *Paths) {
if (a->Parent == nullptr) {
for(int j = 0;j < a->Nodes->Count;j++) {
if ((a->Nodes[j]->ImageIndex == 1)&&(a->Nodes[j]->Checked==true)) {
(*Paths)->Resize((*Paths), (*Paths)->Length + 1);
(*Paths)[(*Paths)->Length-1] = a->Nodes[j];
}
}
}
for(int i = 0;i < a->Nodes->Count;i++) {
if (a->Parent == nullptr) {
FillSelected(a->Nodes[i], Paths);
} else {
if(a->Nodes[i]->Checked == true) {
(*Paths)->Resize((*Paths), (*Paths)->Length + 1);
(*Paths)[(*Paths)->Length-1] = a->Nodes[i];
}
if ((a->Nodes[i]->Nodes->Count > 0)&&(a->Nodes[i]->Nodes[0]->FullPath != (a->Nodes[i]->FullPath + "\\"))) {
FillSelected(a->Nodes[i], Paths);
}
}
}
return;
}
© Stack Overflow or respective owner