views:

21

answers:

1

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;
}
+2  A: 

http://www.google.ru/search?q=not+from+the+thread+in+which+it+was+created%22

Andrey
thx. But i have some questions. If i want to work with some parts of UI element (it is only 3 properties of TreeNode) and i do class and it was MC++ based and have only this properties do this right solution of this problem?
Xaver