Team LiB
Previous Section Next Section

Chapter 15: Threading

Threading Basics

The framework's Thread class provides the means for working with threads. Table 15-1 shows how Win32 relates to threading in the framework.

Table 15-1: Threading in Win32 and the Framework

Win32

Framework

CreateThread

new Thread (new ThreadStart(XXXX))

TerminateThread

Thread.Abort

SuspendThread

Thread.Suspend

ResumeThread

Thread.Resume

Sleep

Thread.Sleep

WaitForSingleObject on a thread handle

Thread.Join

ExitThread

No equivalent

GetCurrentThread

Thread.CurrentThread

SetThreadPriority

Thread.Priority

No equivalent

Thread.Name

No equivalent

Thread.IsBackground

CoInitializeEx

Thread.Apartment

Table 15-2 shows some synchronization object comparisons. You can also use the Synchronization attribute to synchronize access to an entire class if the class inherits from ContextBoundObject. Additionally, you can use MethodImplAttribute(MethodImplOptions.Synchronized ) to synchronize an entire method.

Table 15-2: Synchronization Object Comparisons

Win32

Framework

InterlockedXXXX

InterlockedClass

CriticalSection

lock or Monitor class

Event

AutoResetEvent or ManualResetEvent

Mutex

Mutex


Team LiB
Previous Section Next Section