Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

Name

ThreadState

Synopsis

This enumeration encapsulates the various states a thread may be in. A thread starts in the Unstarted state. Once the Thread.Start( ) method is called, a thread enters the Running state. If another thread calls Thread.Abort( ) at any time, the thread shifts into the AbortRequested state, and then into Aborted once the thread reaches a safe point for garbage collection.

If the running thread calls either the static method Thread.Sleep( ), any of the Wait( ) methods on a WaitHandle, or Thread.Join( ) on another thread, the executing thread enters the WaitSleepJoin state.

If another thread calls Thread.Interrupt( ) on a thread in the WaitSleepJoin state, the thread again enters the Running state. When another thread calls Thread.Suspend( ) on a thread, it enters the SuspendRequested state. Once a thread in the SuspendRequested state reaches a safe point for garbage collection, it enters the Suspended state. A thread then leaves the Suspended state and enters the running state when another thread calls Thread.Resume( ) on it. When a thread has finished running, it enters the Stopped state.

Once a thread has started, it cannot return to the Unstarted state. Similarly, once a thread has aborted or stopped, it cannot return to the Running state. This enumeration is marked with a [Flags( )] attribute, which allows a thread to be in more than one state at a time. For example, if a thread is in the WaitSleepJoin and another thread calls Thread.Abort( ) on it, it will ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# in a Nutshell

C# in a Nutshell

Ben Albahari, Ted Neward, Peter Drayton
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard

Publisher Resources

ISBN: 0596005261Catalog PageErrata