problem in working with thread
- by Xaver
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;
}