Avatar billede agerled Nybegynder
25. februar 2005 - 19:03 Der er 1 løsning

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
Avatar billede agerled Nybegynder
12. marts 2005 - 16:29 #1
lukket.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester