You are previewing Multithreading in C# 5.0 Cookbook.
O'Reilly logo
Multithreading in C# 5.0 Cookbook

Book Description

Multithreaded programming can seem overwhelming but this book clarifies everything through its cookbook approach. Packed with practical tasks, it’s the quick and easy way to start delving deep into the power of multithreading in C#.

  • Covers all the major topics of multithreading, from beginning to advanced

  • Written for the new version of C# 5, and covers async and await keywords

  • Learn how to convert Windows 8 async operations to tasks

  • In Detail

    Processing power is at an ever-higher premium when developing applications. Simple applications written today cost ten-fold what they did a few years ago. Learning how to harness the power provided by multi-core technology, in a professional and efficient manner is becoming increasingly integral to developers

    Multithreading in C# 5.0 Cookbook provides you with practical-first recipes that provides professional guidance in multithreaded and asynchronous programming.

    Starting with basic threads, the book quickly builds on this knowledge to cover ever more advanced and important topics, such as concurrent collections, I/O threads and parallel programming patterns.

    Table of Contents

    1. Multithreading in C# 5.0 Cookbook
      1. Table of Contents
      2. Multithreading in C# 5.0 Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
        2. Why Subscribe?
        3. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Threading Basics
        1. Introduction
        2. Creating a thread in C#
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Pausing a thread
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Making a thread wait
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Aborting a thread
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Determining a thread state
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Thread priority
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Foreground and background threads
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Passing parameters to a thread
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        10. Locking with a C# lock keyword
          1. Getting ready
          2. How to do it...
          3. How it works...
        11. Locking with a Monitor construct
          1. Getting ready
          2. How to do it...
          3. How it works...
        12. Handling exceptions
          1. Getting ready
          2. How to do it...
          3. How it works...
      9. 2. Thread Synchronization
        1. Introduction
        2. Performing basic atomic operations
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Using the Mutex construct
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Using the SemaphoreSlim construct
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        5. Using the AutoResetEvent construct
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Using the ManualResetEventSlim construct
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        7. Using the CountDownEvent construct
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Using the Barrier construct
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Using the ReaderWriterLockSlim construct
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Using the SpinWait construct
          1. Getting ready
          2. How to do it...
          3. How it works...
      10. 3. Using a Thread Pool
        1. Introduction
        2. Invoking a delegate on a thread pool
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Posting an asynchronous operation on a thread pool
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Thread pool and the degree of parallelism
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Implementing a cancellation option
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Using a wait handle and timeout with a thread pool
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        7. Using a timer
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Using the BackgroundWorker component
          1. Getting ready
          2. How to do it...
          3. How it works...
      11. 4. Using Task Parallel Library
        1. Introduction
        2. Creating a task
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Performing basic operations with a task
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Combining tasks together
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Converting the APM pattern to tasks
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Converting the EAP pattern to tasks
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Implementing a cancellation option
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Handling exceptions in tasks
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        9. Running tasks in parallel
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Tweaking tasks execution with TaskScheduler
          1. Getting ready
          2. How to do it...
          3. How it works...
      12. 5. Using C# 5.0
        1. Introduction
        2. Using the await operator to get asynchronous task results
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Using the await operator in a lambda expression
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Using the await operator with consequent asynchronous tasks
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Using the await operator for the execution of parallel asynchronous tasks execution
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Handling exceptions in the asynchronous operations
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Avoid using the captured synchronization context
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Working around the async void method
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Designing a custom awaitable type
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Using the dynamic type with await
          1. Getting ready
          2. How to do it...
          3. How it works...
      13. 6. Using Concurrent Collections
        1. Introduction
        2. Using ConcurrentDictionary
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Implementing asynchronous processing using ConcurrentQueue
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Changing asynchronous processing order ConcurrentStack
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Creating a scalable crawler with ConcurrentBag
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Generalizing asynchronous processing with BlockingCollection
          1. Getting ready
          2. How to do it...
          3. How it works...
      14. 7. Using PLINQ
        1. Introduction
        2. Using the Parallel class
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Parallelizing a LINQ query
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Tweaking the parameters of a PLINQ query
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Handling exceptions in a PLINQ query
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Managing data partitioning in a PLINQ query
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Creating a custom aggregator for a PLINQ query
          1. Getting ready
          2. How to do it...
          3. How it works...
      15. 8. Reactive Extensions
        1. Introduction
        2. Converting a collection to asynchronous Observable
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Writing custom Observable
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Using Subjects
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Creating an Observable object
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Using LINQ queries against the observable collection
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Creating asynchronous operations with Rx
          1. Getting ready
          2. How to do it...
          3. How it works...
      16. 9. Using Asynchronous I/O
        1. Introduction
        2. Working with files asynchronously
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Writing an asynchronous HTTP server and client
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Working with a database asynchronously
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Calling a WCF service asynchronously
          1. Getting ready
          2. How to do it...
          3. How it works...
      17. 10. Parallel Programming Patterns
        1. Introduction
        2. Implementing Lazy-evaluated shared states
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Implementing Parallel Pipeline with BlockingCollection
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Implementing Parallel Pipeline with TPL DataFlow
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Implementing Map/Reduce with PLINQ
          1. Getting ready
          2. How to do it...
          3. How it works...
      18. 11. There's More
        1. Introduction
        2. Using a timer in a Windows Store application
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Using WinRT from usual applications
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Using BackgroundTask in Windows Store applications
          1. Getting ready
          2. How to do it...
          3. How it works...
      19. Index