eksekvere sub i threadpool i baggrunden
Hej.Er der nogen der kan vise mig hvordan jeg kan eksekvere følgende sub i en threadpool i baggrunden??? Sub'en fylder et listview med data fra en DB.
ublic Sub FillList(ByVal SelectedMonth As Integer, ByVal selectedYear As Integer, ByVal SelectedCountry As String)
cmbmonths.cmbMonth.SelectedValue = Util.AddNull(SelectedMonth)
cmbyears.cmbYear.SelectedValue = selectedYear
cmbCountry.cmbCountry.SelectedValue = SelectedCountry
Dim DaysInMonth As Integer = Date.Today.DaysInMonth(selectedYear, SelectedMonth)
CType(myForm, Form1).ProgressStatusBar1.StartProgress("Henter data...")
Try
Dim dsUsers As DataSet
Dim dsantaltest As DataSet
Dim dsBudget As DataSet
dsUsers = Util.FillDataSet("select distinct(medarbejder) as medarbejder,userid from medarbejder where slutdato < startdato and userid <> 0 order by medarbejder", "Users")
dsantaltest = Util.FillDataSet("select extract(day from historikdato) as dag,userid from leasyhistorik where extract(month from historikdato) = " & Util.AddNull(SelectedMonth) & " and extract(year from historikdato) = " & selectedYear & " and type = 'B' and modul = 8 and dataset = '" & SelectedCountry & "' and bemxrkning = 'Tlf.rykker' order by historikdato", "BetalingsaftalerAntal")
dsBudget = Util.FillDataSet("select navn,antal from betalingsaftaler_budget where month = " & Util.AddNull(SelectedMonth) & " and year = " & selectedYear & "", "BetalingsaftalerBudget")
Dim dvAntal As DataView
Dim dvBudget As DataView
dvAntal = New DataView(dsantaltest.Tables("BetalingsaftalerAntal"))
dvBudget = New DataView(dsBudget.Tables("BetalingsaftalerBudget"))
Dim DataRow As DataRow
Dim daycount As Integer
Dim TotBetAft As Integer = 0
lstBetAftMD.Columns.Clear()
lstBetAftMD.Items.Clear()
With lstBetAftMD
.Columns.Add(("Navn"), 56, ContentAlignment.MiddleLeft)
For daycount = 1 To DaysInMonth
.Columns.Add((daycount.ToString()), 28, ContentAlignment.MiddleRight)
Next
.Columns.Add(("Total"), 40, ContentAlignment.MiddleRight)
.Columns.Add((""), 20, ContentAlignment.MiddleLeft)
End With
lstBetAftMD.ImageList = Util.ListViewIcons
Dim item As New GlacialComponents.Controls.GLItem
For Each DataRow In dsUsers.Tables("Users").Rows()
dvAntal.RowFilter = "userid = " & DataRow("userid") & ""
If dvAntal.Count > 0 Then
CType(myForm, Form1).ProgressStatusBar1.ProgressText("Henter data for " & DataRow("medarbejder") & "")
item = lstBetAftMD.Items.Add(DataRow("medarbejder"))
item.SubItems(0).ImageIndex = 0
Dim UserTot As Integer = 0
For daycount = 1 To DaysInMonth
dvAntal.RowFilter = "userid = " & DataRow("userid") & " and dag = " & Util.AddNull(daycount) & ""
If dvAntal.Count > 0 Then
UserTot = UserTot + dvAntal.Count()
item.SubItems(daycount).Text = dvAntal.Count()
Else
item.SubItems(daycount).Text = ""
End If
Next
item.SubItems(DaysInMonth + 1).Text = UserTot
item.SubItems(DaysInMonth + 1).Font = New Font(Me.Font, FontStyle.Bold)
dvBudget.RowFilter = "navn = '" & DataRow("medarbejder") & "'"
If dvBudget.Count > 0 Then
If dvBudget.Item(0).Item("antal") > UserTot Then
item.SubItems(DaysInMonth + 2).Text = ""
item.SubItems(DaysInMonth + 2).ImageIndex = 3
Else
item.SubItems(DaysInMonth + 2).Text = ""
item.SubItems(DaysInMonth + 2).ImageIndex = 1
End If
Else
item.SubItems(DaysInMonth + 2).Text = ""
End If
End If
Next
item = lstBetAftMD.Items.Add("Total")
item.SubItems(0).ImageIndex = 0
For daycount = 1 To DaysInMonth
dvAntal.RowFilter = "dag = " & Util.AddNull(daycount) & ""
If dvAntal.Count > 0 Then
TotBetAft = TotBetAft + dvAntal.Count()
item.SubItems(daycount).Text = dvAntal.Count()
item.SubItems(daycount).Font = New Font(Me.Font, FontStyle.Bold)
Else
item.SubItems(daycount).Text = ""
End If
Next
item.SubItems(DaysInMonth + 1).Text = TotBetAft
item.SubItems(DaysInMonth + 1).Font = New Font(Me.Font, FontStyle.Underline)
CType(myForm, Form1).ProgressStatusBar1.StopProgress()
CType(myForm, Form1).ProgressStatusBar1.ProgressText(lstBetAftMD.Count - 1 & " agenter (" & TotBetAft & " betalingsaftaler)")
dsUsers.Dispose()
dsantaltest.Dispose()
dsBudget.Dispose()
dvAntal.Dispose()
dvBudget.Dispose()
Catch Exp As OracleException
MsgBox(Exp.Message, MsgBoxStyle.Critical, "Oracle Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub