如何知道线程中的工作何时完成? [英] how to know when a work in a thread is complete?
本文介绍了如何知道线程中的工作何时完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
如何知道线程中的工作何时完成?
Hi
how to know when a work in a thread is complete?
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim firstThread As New Thread(AddressOf Fu1)
firstThread.Start()
'I want to determine the job of sub (Fun) is finished and then run other code. Normally if i add other code after firstThread.Start() code is running before completed job of Fun (Codes after firstThread.Start() is depended on finished Fun)
End Sub
Sub Fun()
'Something code is here
End Sub
推荐答案
对于线程,您具有myThread.IsAlive属性.如果线程方法返回或线程被中止,则为false.
查看 MSDN [
For a thread you have the myThread.IsAlive property. It is false if the thread method returned or the thread was aborted.
Look at MSDN [^]for details.
Dim firstThread As New Thread(AddressOf Job1)
Dim SecondThread As New Thread(AddressOf Job2)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
firstThread.Start()
SecondThread.Start()
End Sub
Sub Job1()
'Something code is here
End Sub
Sub Job2()
While (Job1.IsAlive)
End While
'Job 2
End Sub
请期待关于Join方法.
Hi try to look forward on Join method.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim firstThread As New Thread(AddressOf Fu1)
firstThread.Start()
firstThread.Join()
'I want to determine the job of sub (Fun) is finished and then run other code. Normally if i add other code after firstThread.Start() code is running before ompleted job of Fun (Codes after firstThread.Start() is depended on finished Fun)
End Sub
Sub Fun()
'Something code is here
End Sub
这篇关于如何知道线程中的工作何时完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文