如何并行使用线程是这样的?使用顶部索引初始化数组

问题描述 投票:0回答:0

构建数组来加速程序。创建数组后,将数组设置到datagridview。

    Dim myArray(100) As String
    Dim bit1 As Boolean
    Dim bit2 As Boolean
    Dim bit3 As Boolean
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Do you think it is done in parallel?
             Dim thread1 As New Threading.Thread(AddressOf processing1)
          thread1.Start()
               Dim thread2 As New Threading.Thread(AddressOf processing2)
        thread2.Start()
               Dim thread3 As New Threading.Thread(AddressOf processing3)
         thread3.Start()
            While True
         'An infinite loop until the work of the processes is finished
            If (bit1 And bit2 And bit3) Then
                ListBox1.Items.AddRange(myArray)
                Exit While
            End If
        End While
        End Sub
    Sub processing1()
     'From 0 to 30 To make Part of the array
        For a = 0 To 30 
             myArray(a) = a
        Next
          bit1 = True
    End Sub
    Sub processing2()
      'From 31 to 60 To make Part of the array
        For a = 31 To 60 
            myArray(a) = a
        Next
        bit2 = True
    End Sub
    Sub processing3()
         'From 60 to 100 To make Part of the array
        For a = 60 To 100
            myArray(a) = a
        Next
        bit3 = True
    End Sub

这里我用的是ListBox,但是应该用在DataTable或者DataGridView中。 什么是并行化流程的更快方法?

vb.net multithreading parallel-processing datagridview
© www.soinside.com 2019 - 2024. All rights reserved.