Here are some key points that I’ve found while going through the Threading chapter.
- To perform work concurrently, use the Thread class.
- To start thread execution, use the Thread class’s Start method.
- To wait on threads to complete, use the Thread class’s Join method.
- To cancel execution of a thread, use the Thread class’s Abort method.
- To share data across threads, use the ExecutionContext class.
- To perform atomic math operations, use the Interlock class.
- To lock data, use the C# lock or the Visual Basic SyncLock syntax.
- To lock data with a synchronization object, use the Monitor class.
- To lock data where multiple readers can access data at once but one writer at a time can change data, use a ReaderWriterLock.
- To synchronize threads across AppDomains or process boundaries, use a Mutex.
- To throttle threads with a resource-based synchronization object, use a Semaphore.
- To signal threads across AppDomains or process boundaries, use an Event.
- The Thread class can be used to create multiple paths for simultaneous execution in your own applications.
- Using the lock (SyncLock in Visual Basic) keyword will allow you to write threadsafe access to your code’s data.
- You must be careful in writing thread-safe code to avoid deadlock situations.
- The ReaderWriterLock class can be used to write thread-safe code that is less prone to allowing only a single thread at a time to access its data.
- The WaitHandle derived classes (Mutex, Semaphore, and Event classes) exemplify Windows operating-system-level synchronization objects.
- Much of the .NET Framework supports the Asynchronous Programming Model (APM) to allow for asynchronous execution of code without having to directly deal with the ThreadPool or Threads.
- The ThreadPool is a convenient class that enables fast creation of threads for queuing up code to run as well as for waiting for WaitHandle derived objects.
- Timers are useful objects for firing off code on separate threads at specific intervals.
Extracted from MCTS(70-536) Application Development Foundation
Advertisement