一个进程vb.net的多线程

时间:2016-11-10 08:38:14

标签: vb.net multithreading process

我刚刚在VB.net中学到了一些基于多线程的基础知识,因为我需要为一个进程进行多线程处理 我的代码是:



Private Sub btnLoadNow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim T1 As New Thread(AddressOf myprocess)
    T1.Start()

    Dim T2 As New Thread(AddressOf myprocess)
    T2.Start()

    Dim T3 As New Thread(AddressOf myprocess)
    T3.Start()

    Dim T4 As New Thread(AddressOf myprocess)
    T4.Start()

    Dim T5 As New Thread(AddressOf myprocess)
    T5.Start()

End Sub

Private Sub myprocess()
   'my Process Codes

End Sub




但是这段代码有错误我该怎么做呢?

1 个答案:

答案 0 :(得分:-1)

您没有定义自动加载

Dim T1 As New Thread(AddressOf AutoLoad)

只需更换AutoLoad ---> myprocess

Dim T1 As New Thread(AddressOf myprocess)

AND

Private Sub myprocess()
   'my Process Codes
Next

Sub必须以End Sub结尾

Private Sub myprocess()
       'my Process Codes
End Sub

此代码正在运作

Imports System.Threading
Module Module1

    Sub Main()
        Dim T1, T2, T3, T4 As Thread

        T1 = New Thread(AddressOf myprocess)
        T2 = New Thread(AddressOf myprocess)
        T3 = New Thread(AddressOf myprocess)
        T4 = New Thread(AddressOf myprocess)

        T1.Start()
        T2.Start()
        T3.Start()
        T4.Start()

    End Sub

    Private Sub myprocess()
      'some code
    End Sub

End Module