clintnash
asked on
Convert code to use threading
I have a winform app that loads a large quantity of data into a datagrid at start, the apps responsiveness once the data is loaded is good, but after the uses logs in the app looks like it has hung, the login box becomes and empty white square and the main form doesnt load for up to a minute and an half while the dataset that feeds the datagrid is being loaded. After a little research I think the best method to resolve this is to put the sub that fills the dataset an binds to the datagrid into its own thread (at this point if someone has a better approach please let me know). With that said, I started trying to find a few examples that explained threading in a way I could implement into my code. What I found were a number of simple examples that left me confused (this makes absolutely no sense to me at all).
This is roughly the code in my main form.
Private Sub Form1_Load(ByVal sender ....
Get_Data()
... do other stuff
End Sub
Private Sub Get_Data()
Dim strConn As String = CType(ConfigurationSetting s.AppSetti ngs("conne ctionStrin g"), String)
Dim ds As DataSet
Dim distinctds As DataSet
ds = SqlHelper.ExecuteDataset(s trConn, "sp_camps_reg_players", Integer.Parse(lblActiveSea son.Text))
Dim dt As DataTable
Dim dt1 As DataTable
dt = ds.Tables.Item(0)
'DistinctList is creating by another sub that takes a datatable
'and returns a dataset that has the duplicates removed from it
distinctds = DistinctList(dt, "playerid")
dt1 = distinctds.Tables.Item(0)
dv = New DataView(dt1)
DataGrid1.AutoGenerateColu mns = False
DataGrid1.DataSource = dv
txtfilter.Focus()
End Sub
I am not sure if it matter but the above sub does call another sub (called DistinctList). Any advice on how to approach this problem will be greatly appreciated.
Thanks,
Clint...
This is roughly the code in my main form.
Private Sub Form1_Load(ByVal sender ....
Get_Data()
... do other stuff
End Sub
Private Sub Get_Data()
Dim strConn As String = CType(ConfigurationSetting
Dim ds As DataSet
Dim distinctds As DataSet
ds = SqlHelper.ExecuteDataset(s
Dim dt As DataTable
Dim dt1 As DataTable
dt = ds.Tables.Item(0)
'DistinctList is creating by another sub that takes a datatable
'and returns a dataset that has the duplicates removed from it
distinctds = DistinctList(dt, "playerid")
dt1 = distinctds.Tables.Item(0)
dv = New DataView(dt1)
DataGrid1.AutoGenerateColu
DataGrid1.DataSource = dv
txtfilter.Focus()
End Sub
I am not sure if it matter but the above sub does call another sub (called DistinctList). Any advice on how to approach this problem will be greatly appreciated.
Thanks,
Clint...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Private Function GetData()
Dim strConn As String = CType(ConfigurationSetting
.. other code
dv = New DataView(dt1)
Return dv
End Function
Private Sub BackgroundWorker1_DoWork(B
e.Result = GetData()
End Sub
Private Sub BackgroundWorker1_RunWorke
Dim returnedData As DataView = TryCast(e.Result, DataView)
DataGrid1.AutoGenerateColu
DataGrid1.DataSource = returnedData
lblLoading.Text = "Data loaded successfully"
End Sub
Thanks again for your help,
Clint