这次我们来学Thread的属性 Thread.ThreadState 返回线程状态,乐博网通过代码控制,让大家可以更清楚的看到线程在运行中所处的各种状态。
运行结果:
代码如下:
Imports Microsoft.VisualBasic Imports System Imports System.Threading
Public Class LobDotCn
Shared Sub Main()
Dim newThread As Thread = New Thread(AddressOf ThreadMethod) Console.WriteLine("ThreadState: {0}", newThread.ThreadState) '此时线程还未启动 newThread.Start() Console.WriteLine("ThreadState: {0}", newThread.ThreadState)'线程已经启动,工作开始 Thread.Sleep(1000) Console.WriteLine("ThreadState: {0}", newThread.ThreadState)'线程挂起或者等待中 newThread.Join() '通过jion()方法,直到线程已经结束再继续 Console.WriteLine("ThreadState: {0}", newThread.ThreadState)'此时线程已经停止 Console.ReadLine()
End Sub
'更多原创VB.Net学习笔记,来自lob.cn乐博网
Shared Sub ThreadMethod()
Thread.Sleep(5000)
End Sub
End Class
|
阅读(255) | 评论(0) | 转发(0) |