Herman
Well-known member
Hello fellow codemonkeys... I have a small problem that I am sure is due mostly to my inexperience with threading. I have used simple entirely self-contained threads before, but not to a great extent. I understand the basic laws that surround them, such as how a thread cannot access another thread's member directly, and must use delegates.
Consider the following chunk of code:
I have been scratching my head as to how I should devise a threading strategy so that these statements are executed in their own thread:
As you see, the problematic is the Datatable return object, which needs to be accessed from the calling thread.
Any help would be greatly appreciated.
A little extra background... This method is part of my form code, and the goal I wish to achieve through threading these statements is greater UI responsiveness. I deliberately took the simplest method I could find. Am I going about this the wrong way?
Consider the following chunk of code:
VB.NET:
' This sub refreshes the server list.
Private Sub RefreshServerList()
' Update the status bar.
UpdateProgressBar("Refreshing server list...", 50, 100)
' Clear the server list.
lstServers.Items.Clear()
lstServers.SelectedIndex = -1
' Instanciate the SQL data source enumerator.
Dim SQLInstance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
Dim dataInstanceList As System.Data.DataTable = SQLInstance.GetDataSources()
' Populate the server list.
For Each Row As DataRow In dataInstanceList.Rows
lstServers.Items.Add(Row(0).ToString & "\" & Row(1).ToString)
Next
' Clear the status bar.
UpdateProgressBar("", 0, 100)
End Sub
I have been scratching my head as to how I should devise a threading strategy so that these statements are executed in their own thread:
VB.NET:
Dim SQLInstance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
Dim dataInstanceList As System.Data.DataTable = SQLInstance.GetDataSources()
As you see, the problematic is the Datatable return object, which needs to be accessed from the calling thread.
Any help would be greatly appreciated.
A little extra background... This method is part of my form code, and the goal I wish to achieve through threading these statements is greater UI responsiveness. I deliberately took the simplest method I could find. Am I going about this the wrong way?