等到线程完成后再运行下一步

时间:2018-07-22 10:26:23

标签: vb.net multithreading

我有执行多线程的代码,我想等到第二个线程完成后,再执行下一步,但是我的代码不是在等待线程完成。我的代码:

typing("hello world")
'I want to wait until this thread finishes,
'then continue executing the next MsgBox step.
MsgBox("hello")

Function typing(k As String)
    Dim th As New Thread(DirectCast(Function() runs(k), ThreadStart))
    th.IsBackground = True
    th.Start()
End Function

Function runs(ByVal k As String)
    For q As Integer = 0 To k.Length - 1
        Dim ss As String = k.Substring(q, 1)
        If Convert.ToChar(ss) >= "a" And Convert.ToChar(ss) <= "z" Then
            keybd_event(&H15, MapVirtualKey(&H15, 0), 0, 0) ' 
        End If
    Next
End Function

0 个答案:

没有答案