Greetings,
I know this must not be the proper way to do this but I am stumped. The following code loops through a treeview branch and get the description for each computer. When a compute is not present on the network, it takes much longer for the routine to return. So I am using threads. There might be 300+ machines to query, so I don’t want to start more than nine threads at a time. The WHILE loop is meant to keep the thread count less than ten. Now a couple scenarios:
1. Without the WHILE loop at all, the code works as planed. It works better, however, on a branch with <50 or so items as there is no limit on the number of threads started.
2. With the WHILE loop as it is shown, the program appears to sleep forever (even if the SLEEP is commented out. It has to be stopped as it won’t respond to a close.
3. With the WHILE loop as it is shown, and with the MSGBOX line uncommented, it works as it should. Limiting the threadcount, but obviously making me close each msgbox as it pops up. The program behaves normally and will shut down when told to close.
Regards,
David
I know this must not be the proper way to do this but I am stumped. The following code loops through a treeview branch and get the description for each computer. When a compute is not present on the network, it takes much longer for the routine to return. So I am using threads. There might be 300+ machines to query, so I don’t want to start more than nine threads at a time. The WHILE loop is meant to keep the thread count less than ten. Now a couple scenarios:
1. Without the WHILE loop at all, the code works as planed. It works better, however, on a branch with <50 or so items as there is no limit on the number of threads started.
2. With the WHILE loop as it is shown, the program appears to sleep forever (even if the SLEEP is commented out. It has to be stopped as it won’t respond to a close.
3. With the WHILE loop as it is shown, and with the MSGBOX line uncommented, it works as it should. Limiting the threadcount, but obviously making me close each msgbox as it pops up. The program behaves normally and will shut down when told to close.
Code:
Function FORM1_BN_CLICKED ( _ ControlIndex As Long, _ ' index in Control Array hWndForm As Dword, _ ' handle of Form hWndControl As Dword, _ ' handle of Control idButtonControl As Long _ ' identifier of button ) As Long Local i As Long Local hTreeItem As Long Local hChildItem As Long Local sComputer As String hTreeItem=TreeView_GetSelection(HWND_FORM1_TREEVIEW1) If FF_TreeView_GetLevel (HWND_FORM1_TREEVIEW1, hTreeItem)=2 Then 'Pointing to a computer hTreeItem=(TreeView_GetParent(HWND_FORM1_TREEVIEW1,hTreeItem)) ' get its parent End If hChildItem=TreeView_GetChild(HWND_FORM1_TREEVIEW1,hTreeItem) While hChildItem<>%Null 'sComputer=FF_TreeView_GetText (HWND_FORM1_TREEVIEW1, hChildItem) ' the above line was commented out because it wasn't being used and was therefore misleading While ThreadCount>9 Sleep 200 'msgbox str$(threadcount) Wend Thread Create get_description(hChildItem) To hTreeItem hChildItem=TreeView_GetNextSibling(HWND_FORM1_TREEVIEW1,hchildItem) Wend End Function
David
Comment