nNote Another special parameter value for Thread.Sleep() is 0. If you pass 0, Thread.Sleep() will
cause the thread to relinquish the rest of its time slice. The thread will then be allowed to run again once the
system thread scheduler comes back around to it.
CHAPTER 13 n THREADING 279
Another way to put a thread to sleep for an indefinite amount of time is via the Thread.
Suspend instance method. Calling Suspend() suspends execution of the thread until it is
explicitly resumed. You can resume the thread by calling the Resume instance method or
Interrupt(). However, the target thread will need an exception handler around the Suspend()
call; otherwise, the thread will exit. Technically, calling Abort() on the thread will resume the
thread, but only to send it a ThreadAbortException and cause the thread to exit. Keep in mind
that any thread with sufficient privileges can call Suspend() on a thread??”even the current
thread can call Suspend(). If the current thread calls Suspend(), it blocks at that point, waiting
for the next Resume() call.
When you call Suspend() on a thread, the thread is not suspended immediately in its
tracks. Instead, the thread is allowed to execute to what??™s called a safe point. Once it reaches
the safe point, the thread is suspended.
Pages:
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452