J
John Cosmas
I've developed a THREAD, which takes it time and does some inquiries for me
from a database. Then, I've writing the results into a TREEVIEW, but the
THREAD code generates an error - "The action being performed on this
control is being called from the wrong thread. You must marshal to the
correct thread using Control.Invoke or Control.BeginInvoke to perform this
action" - whenever it tries to populate the TREEVIEW nodes.
My code does this....
Sub Form_Load...
Dim pobj100Thread As Thread
pobj100Thread = New Thread(AddressOf ps_List_Servers)
pobj100Thread.Start()
End Sub
Private Sub ps_List_Servers()
Dim pobjSQLApp As New SQLDMO.Application
Dim pobjSQLNames As SQLDMO.NameList
Dim pint300Temp As Integer
Dim pint350Temp As Integer = 0
pobjSQLNames = pobjSQLApp.ListAvailableSQLServers
With Me.ctlLogsTreeVw
.BeginUpdate()
For pint300Temp = 1 To pobjSQLNames.Count
If pobjSQLNames.Item(pint300Temp) <> "(local)" Then
.Nodes(0).Nodes.Add(New
TreeNode(pobjSQLNames.Item(pint300Temp)))
.Nodes(0).Nodes(pint350Temp).Tag = "Server"
pint350Temp = pint350Temp + 1
End If
Next
.EndUpdate()
End With
End Sub
from a database. Then, I've writing the results into a TREEVIEW, but the
THREAD code generates an error - "The action being performed on this
control is being called from the wrong thread. You must marshal to the
correct thread using Control.Invoke or Control.BeginInvoke to perform this
action" - whenever it tries to populate the TREEVIEW nodes.
My code does this....
Sub Form_Load...
Dim pobj100Thread As Thread
pobj100Thread = New Thread(AddressOf ps_List_Servers)
pobj100Thread.Start()
End Sub
Private Sub ps_List_Servers()
Dim pobjSQLApp As New SQLDMO.Application
Dim pobjSQLNames As SQLDMO.NameList
Dim pint300Temp As Integer
Dim pint350Temp As Integer = 0
pobjSQLNames = pobjSQLApp.ListAvailableSQLServers
With Me.ctlLogsTreeVw
.BeginUpdate()
For pint300Temp = 1 To pobjSQLNames.Count
If pobjSQLNames.Item(pint300Temp) <> "(local)" Then
.Nodes(0).Nodes.Add(New
TreeNode(pobjSQLNames.Item(pint300Temp)))
.Nodes(0).Nodes(pint350Temp).Tag = "Server"
pint350Temp = pint350Temp + 1
End If
Next
.EndUpdate()
End With
End Sub