The framework's Thread class provides the means for working with threads. Table 15-1 shows how Win32 relates to threading in 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.
|
Win32 |
Framework |
|---|---|
|
InterlockedXXXX |
InterlockedClass |
|
CriticalSection |
lock or Monitor class |
|
Event |
AutoResetEvent or ManualResetEvent |
|
Mutex |
Mutex |