背景工人和线程

时间:2015-03-25 09:13:06

标签: vb.net multithreading backgroundworker vb.net-2010

我正在使用带有计时器的后台工作程序来调用具有for循环的函数...如下所示:

 Private Sub t_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t.Tick
        t.Enabled = False
        t.Interval = 5000
        Start()
End Sub

 Sub Start()
    If frm10BckWorker.IsBusy <> True Then
        frm10BckWorker.WorkerReportsProgress = True
        frm10BckWorker.RunWorkerAsync()
    End If
End Sub

 Private Sub frm2BckWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles frm10BckWorker.DoWork
    StartSending()
End Sub

 Sub StartSending()
    Try
        f.GetNumbers("JK_SP_GET_Users_TO_PROCEED", UsersBulkCnx(8))

        count = f.numbersTable.Rows.Count
        If count = 0 Then Exit Sub

        For I = 0 To count - 1

            Id = Trim(f.GetReaderValue(f.numbersTable.Rows(I).Item("ID")))
            MO = Trim(f.GetReaderValue(f.numbersTable.Rows(I).Item("MO")))
            FamilyName = Trim(f.GetReaderValue(f.numbersTable.Rows(I).Item("FamilyName")))
            CName = Trim(f.GetReaderValue(f.numbersTable.Rows(I).Item("ContactNAme")))
            ImageUrl = Trim(f.GetReaderValue(f.numbersTable.Rows(I).Item("ImageUrl")))

            If Not f.InsertUsers(MO, FamilyName, CName,UsersCnx(8)) Then
                PROC = -1
            End If

            f.DeleteBulk(Id, BulkNbrCnx(8))
            f.InsertHistory(MO, FamilyName, CName,ImageUrl, UsersBulkCnx(8))

        Next
    Catch ex As Exception
        f.WriteToText("StartSending", ex.ToString)
    End Try
End Sub

我需要的是在后台运行这个函数f.InsertHistory我在for循环中调用并保持循环运行,而不等待此函数结束转到循环中的下一条记录,

有什么建议吗?

0 个答案:

没有答案