如何搭配 Sleep 方法來使用 TimeSpan 值的作法。
Visual Basic
Imports System
Imports System.Threading
Public Class Test
Shared waitTime As New TimeSpan(0, 0, 1)
<MTAThread> _
Shared Sub Main()
Dim newThread As New Thread(AddressOf Work)
newThread.Start()
If newThread.Join( _
TimeSpan.op_Addition(waitTime, waitTime)) Then
Console.WriteLine("New thread terminated.")
Else
Console.WriteLine("Join timed out.")
End If
End Sub
Shared Sub Work()
Thread.Sleep(waitTime)
End Sub
End Class
沒有留言:
張貼留言