Prev | Current Page 442 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Even
when a thread is blocked from calling Join(), you can awaken it by calling Interrupt() or
Abort(), as described in the previous section.
Sometimes, you??™ll want to call Join() to wait on another thread to complete, but you
won??™t want to get stuck waiting forever. Join() offers overloads that allow you to designate the
amount of time you??™re willing to wait. Those overloads return a Boolean value that returns True
to indicate that the thread actually terminated or returns False to indicate that the time-out
expired.
Foreground and Background Threads
When you create a thread in the .NET managed environment, it exists as a foreground thread
by default. This means that the managed execution environment, and thus the process, will
remain alive as long as the thread is alive. Consider the following code:
Imports System
Imports System.Threading
CHAPTER 13 n THREADING 280
Public Class EntryPoint
Private Shared Sub ThreadFunc1()
Thread.Sleep(5000)
Console.WriteLine("Exiting extra thread at " & Now() & ".")
End Sub
Shared Sub Main()
Dim thread1 As Thread = _
New Thread(AddressOf EntryPoint.ThreadFunc1)
thread1.Start()
Console.WriteLine("Exiting main thread at " & Now() & ".")
End Sub
End Class
Running the previous code returns the following results:
Exiting main thread at 10/9/2007 3:56:50 AM.


Pages:
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
Tango Olsztyn pozycjonowanie typy bukmacherskie dieta light mieszkania