Some key points to remember on Threading

by

Here are some key points that I’ve found while going through the Threading chapter.

  1. To perform work concurrently, use the Thread class.
  2. To start thread execution, use the Thread class’s Start method.
  3. To wait on threads to complete, use the Thread class’s Join method.
  4. To cancel execution of a thread, use the Thread class’s Abort method.
  5. To share data across threads, use the ExecutionContext class.
  6. To perform atomic math operations, use the Interlock class.
  7. To lock data, use the C# lock or the Visual Basic SyncLock syntax.
  8. To lock data with a synchronization object, use the Monitor class.
  9. To lock data where multiple readers can access data at once but one writer at a time can change data, use a ReaderWriterLock.
  10. To synchronize threads across AppDomains or process boundaries, use a Mutex.
  11. To throttle threads with a resource-based synchronization object, use a Semaphore.
  12. To signal threads across AppDomains or process boundaries, use an Event.
  13. The Thread class can be used to create multiple paths for simultaneous execution in your own applications.
  14. Using the lock (SyncLock in Visual Basic) keyword will allow you to write threadsafe access to your code’s data.
  15. You must be careful in writing thread-safe code to avoid deadlock situations.
  16. 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.
  17. The WaitHandle derived classes (Mutex, Semaphore, and Event classes) exemplify Windows operating-system-level synchronization objects.
  18. 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.
  19. 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.
  20. Timers are useful objects for firing off code on separate threads at specific intervals.

Extracted from MCTS(70-536) Application Development Foundation

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.