0

我正在使用同步线程,但是当线程启动时,我无法点击我的应用程序上的任何东西......但即使线程计时器开启,我也需要在应用程序上做一些工作,所以我该怎么做?

请注意,我在 vs 2010 上使用 vb.net

这是我的代码:

Private Shared thread As New System.Threading.AutoResetEvent(False) 

Private Sub start_btn_Click(sender As System.Object, e As System.EventArgs) Handles start_btn.Click
    StartTask()
End Sub

Sub StartTask()
    Dim Tpool As System.Threading.ThreadPool
    Dim arg As String = "SomeArg"
    ThreadPool.QueueUserWorkItem(New System.Threading.WaitCallback( _
       AddressOf Task), arg)  ' Queue a task.
    thread.WaitOne() ' Wait for the thread to call Set.
    writeMsg("Thread is done. at ", "list_rpt")
    StartTask()
End Sub

Sub Task(ByVal Arg As Object)
    writeMsg("Thread is starting at ", "list_rpt")
    System.Threading.Thread.Sleep(4000) ' Wait 4 seconds.
    DoWork()
End Sub

Public Sub DoWork()
    MTProcessTable = selectMtProcess()
    mtCount = MTProcessTable.Rows.Count
    writeMsg(mtCount & " rows selected at ", "list_rpt")

    For Each row As DataRow In MTProcessTable.Rows
        process = New Process_class
        process.id = row("mt_id")
        process.mo = row("mt_mo")
        process.mt = row("mt_mt")
        process.datain = row("mt_datain")

        keyid = validateKey(process.datain)
        MOTable = selectMO(process.mo, process.mt)
        moRowNb = MOTable.Rows.Count()
        MO = New MO_class
        If moRowNb <> 0 Then
            MOrow = MOTable.Rows(0)
            MO.newuser = MOrow("newuser")
            MO.sim_id = MOrow("sim_id")
        End If
        Try
            Select Case keyid
                Case 1
                    If moRowNb = 0 Then
                        If insertMO(process.mo, process.mt) Then
                            writeMsg("1 MO inserted/updated at ", "rpt_txt")
                            message = msgTable.Rows(0)(1).ToString()
                            MsgBox(message)
                        Else
                            writeMsg("1 MO could not be inserted at ", "rpt_txt")
                         End If
                   End if
                Case 2
                    If moRowNb = 0 Then
                        writeMsg("1 process with MO not active and datain 'yes' at ", "rpt_txt")
                        message = msgTable.Rows(7)(1).ToString()
                        MsgBox(message)
                    End if
        Catch ex As Exception
            logFile("executeTimer ----" & ex.Message)
            updateProcessed(process.id, ex.Message, 10)
        Finally
            updateProcessed(process.id, message, 1)
        End Try
    Next row
    thread.Set()
End Sub
4

0 回答 0