I have a code which populates data in a datarepeater control, but that takes about 10 secs to load and freezes the UI so i though of using a backgroundworker.
But when I use the code in the backgroundworker it gives me saying 'Additional information: Object reference not set to an instance of an object.' as soon it reaches the datarepeater.Controls("namee of control").Text
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
'Sleep for a second, then update the textbox.
Thread.Sleep(1000)
Me.DataTableServicesTableAdapter.FillByBarberId(Me.ServicesDataSet.DataTableServices, barberId)
Dim drNew As DataRow
drNew = Me.ServicesDataSet.DataTableServices.NewRow()
drNew.Item(2) = "Please select service"
drNew.Item(3) = 0
drNew.Item(9) = 0
Me.ServicesDataSet.DataTableServices.Rows.InsertAt(drNew, 0)
Dim currentItem As Microsoft.VisualBasic.PowerPacks.DataRepeaterItem
Dim queueinClass As New IQB.cQueuing
For i As Integer = 0 To DataRepeater1.ItemCount - 1
DataRepeater1.CurrentItemIndex = i
currentItem = DataRepeater1.CurrentItem
Dim ServiceName As String = currentItem.Controls("NameLabel1").Text.Trim
Dim sTime As Integer = currentItem.Controls("EstWaitTimeLabel1").Text
Dim lblTime As Label = currentItem.Controls("EstWaitTimeLabel1")
Dim Price As Double = currentItem.Controls("PriceLabel1").Text
Dim lblPrice As Label = currentItem.Controls("PriceLabel1")
' set values
' Dim currency = CultureInfo.CurrentCulture
Dim currencySymbol As String = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol
lblPrice.Text = currencySymbol & Math.Round(Price, 2)
' get estimated wait time
Dim total As Integer = sTime
Dim TotalMinute As Int32
Dim Minute As Int32
Dim Hour As Int32
Try
TotalMinute = CType(total, Int32)
TotalMinute = TotalMinute Mod 1440
Hour = TotalMinute \ 60
Minute = TotalMinute Mod 60
If Hour = 0 And Minute = 0 Then
lblTime.Text = Hour & ":" & Form1.FormatTwoDigits(Minute) + " Mins"
End If
If Hour = 1 And Minute = 0 Then
lblTime.Text = Hour & ":" & Form1.FormatTwoDigits(Minute) + " Hour"
End If
If Hour > 1 And Minute = 0 Then
lblTime.Text = Hour & ":" & Form1.FormatTwoDigits(Minute) + " Hours"
End If
If Hour >= 1 And Minute <> 0 Then
lblTime.Text = Hour & ":" & Form1.FormatTwoDigits(Minute) + " Mins"
End If
If Hour = 0 And Minute > 0 Then
lblTime.Text = Hour & ":" & Form1.FormatTwoDigits(Minute) + " Mins"
End If
Catch ex As Exception
End Try
If ServiceName = "Please select service" Then
lblTime.Text = ""
lblPrice.Text = ""
End If
Next
End Sub