
Multithreading in C# 5.0 Cookbook
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
- Scale out your server applications effectively
- Master C# 5.0 asynchronous operations language support
Book DescriptionIn an age when computer processors are being developed to contain more and more cores, multithreading is a key factor for creating scalable, effective, and responsive applications. If you fail to do it correctly, it can lead to puzzling problems that take a huge amount of time to resolve. Therefore, having a solid understanding of multithreading is a must for the modern application developer. Multithreading in C# 5.0 Cookbook is an easy-to-understand guide to the most puzzling programming problems. This book will guide you through practical examples dedicated to various aspects of multithreading in C# on Windows and will give you a good basis of practical knowledge which you can then use to program your own scalable and reliable multithreaded applications. This book guides you through asynchronous and parallel programming from basic examples to practical, real-world solutions to complex problems. You will start from the very beginning, learning what a thread is, and then proceed to learn new concepts based on the information you get from the previous examples. After describing the basics of threading, you will be able to grasp more advanced concepts like Task Parallel Library and C# asynchronous functions. Then, we move towards parallel programming, starting with basic data structures and gradually progressing to the more advanced patterns. The book concludes with a discussion of the specifics of Windows 8 application programming, giving you a complete understanding of how Windows 8 applications are different and how to program asynchronous applications for Windows 8.What you will learn - Work with raw threads, synchronize threads, and coordinate their work
- Work effectively with a thread pool
- Develop your own asynchronous API with Task Parallel Library
- Use C# 5.0 asynchronous language features
- Scale up your server application with I/O threads
- Parallelize your LINQ queries with PLINQ
- Use common concurrent collections
- Apply different parallel programming patterns
- Work with Windows 8 asynchronous APIs
- Use Reactive Extensions to run asynchronous operations and manage their options
Who this book is forIf you are a developer or new to multithreaded programming and you are looking for a quick and easy way to get started, then this book is for you. It is assumed that you have some experience in C# and.NET already, and you should also be familiar with computer science and basic algorithms and data structure
All prices
More details
Other editions
Additional editions

Person
Eugene Agafonov leads Lingvo Live development department at ABBYY, and lives and works in Moscow. He has over 15 years of professional experience in software development, and started to work with C# since it was in beta version. He is Microsoft MVP in ASP.NET since 2006 and he often speaks at local software development conferences, like DevCon Russia, about cutting edge technologies in modern web and server-side application development. His main professional interests are cloud-based software architecture, scalability and reliability. Eugene is a huge fan of football and plays the guitar with a local rock band. You can reach him at his personal blog eugeneagafonov.com or twitter @eugene_agafonov. 3. Other books you may have worked on. Multithreading in C# 5.0 Cookbook 4. Acknowledgements - people you'd like to thank for their help in producing this book, (friends, family, etc) - this part is written in the first person. I'd like it just to be a dedication To Mom and Dad - you are the best parents on Earth and I love you so much
Content
- Intro
- Multithreading in C# 5.0 Cookbook
- Table of Contents
- Multithreading in C# 5.0 Cookbook
- Credits
- About the Author
- About the Reviewers
- www.PacktPub.com
- Support files, eBooks, discount offers and more
- Why Subscribe?
- Free Access for Packt account holders
- Preface
- What this book covers
- What you need for this book
- Who this book is for
- Conventions
- Reader feedback
- Customer support
- Downloading the example code
- Errata
- Piracy
- Questions
- 1. Threading Basics
- Introduction
- Creating a thread in C#
- Getting ready
- How to do it...
- How it works...
- Pausing a thread
- Getting ready
- How to do it...
- How it works...
- Making a thread wait
- Getting ready
- How to do it...
- How it works...
- Aborting a thread
- Getting ready
- How to do it...
- How it works...
- Determining a thread state
- Getting ready
- How to do it...
- How it works...
- Thread priority
- Getting ready
- How to do it...
- How it works...
- Foreground and background threads
- Getting ready
- How to do it...
- How it works...
- Passing parameters to a thread
- Getting ready
- How to do it...
- How it works...
- There's more.
- Locking with a C# lock keyword
- Getting ready
- How to do it...
- How it works...
- Locking with a Monitor construct
- Getting ready
- How to do it...
- How it works...
- Handling exceptions
- Getting ready
- How to do it...
- How it works...
- 2. Thread Synchronization
- Introduction
- Performing basic atomic operations
- Getting ready
- How to do it...
- How it works...
- Using the Mutex construct
- Getting ready
- How to do it...
- How it works...
- Using the SemaphoreSlim construct
- Getting ready
- How to do it...
- How it works...
- There's more.
- Using the AutoResetEvent construct
- Getting ready
- How to do it...
- How it works...
- Using the ManualResetEventSlim construct
- Getting ready
- How to do it...
- How it works...
- There's more.
- Using the CountDownEvent construct
- Getting ready
- How to do it...
- How it works...
- Using the Barrier construct
- Getting ready
- How to do it...
- How it works...
- Using the ReaderWriterLockSlim construct
- Getting ready
- How to do it...
- How it works...
- Using the SpinWait construct
- Getting ready
- How to do it...
- How it works...
- 3. Using a Thread Pool
- Introduction
- Invoking a delegate on a thread pool
- Getting ready
- How to do it...
- How it works...
- Posting an asynchronous operation on a thread pool
- Getting ready
- How to do it...
- How it works...
- Thread pool and the degree of parallelism
- Getting ready
- How to do it...
- How it works...
- Implementing a cancellation option
- Getting ready
- How to do it...
- How it works...
- Using a wait handle and timeout with a thread pool
- Getting ready
- How to do it...
- How it works...
- There's more.
- Using a timer
- Getting ready
- How to do it...
- How it works...
- Using the BackgroundWorker component
- Getting ready
- How to do it...
- How it works...
- 4. Using Task Parallel Library
- Introduction
- Creating a task
- Getting ready
- How to do it...
- How it works...
- Performing basic operations with a task
- Getting ready
- How to do it...
- How it works...
- Combining tasks together
- Getting ready
- How to do it...
- How it works...
- Converting the APM pattern to tasks
- Getting ready
- How to do it...
- How it works...
- Converting the EAP pattern to tasks
- Getting ready
- How to do it...
- How it works...
- Implementing a cancellation option
- Getting ready
- How to do it...
- How it works...
- Handling exceptions in tasks
- Getting ready
- How to do it...
- How it works...
- There's more.
- Running tasks in parallel
- Getting ready
- How to do it...
- How it works...
- Tweaking tasks execution with TaskScheduler
- Getting ready
- How to do it...
- How it works...
- 5. Using C# 5.0
- Introduction
- Using the await operator to get asynchronous task results
- Getting ready
- How to do it...
- How it works...
- Using the await operator in a lambda expression
- Getting ready
- How to do it...
- How it works...
- Using the await operator with consequent asynchronous tasks
- Getting ready
- How to do it...
- How it works...
- Using the await operator for the execution of parallel asynchronous tasks execution
- Getting ready
- How to do it...
- How it works...
- Handling exceptions in the asynchronous operations
- Getting ready
- How to do it...
- How it works...
- Avoid using the captured synchronization context
- Getting ready
- How to do it...
- How it works...
- Working around the async void method
- Getting ready
- How to do it...
- How it works...
- Designing a custom awaitable type
- Getting ready
- How to do it...
- How it works...
- Using the dynamic type with await
- Getting ready
- How to do it...
- How it works...
- 6. Using Concurrent Collections
- Introduction
- Using ConcurrentDictionary
- Getting ready
- How to do it...
- How it works...
- Implementing asynchronous processing using ConcurrentQueue
- Getting ready
- How to do it...
- How it works...
- Changing asynchronous processing order ConcurrentStack
- Getting ready
- How to do it...
- How it works...
- Creating a scalable crawler with ConcurrentBag
- Getting ready
- How to do it...
- How it works...
- Generalizing asynchronous processing with BlockingCollection
- Getting ready
- How to do it...
- How it works...
- 7. Using PLINQ
- Introduction
- Using the Parallel class
- Getting ready
- How to do it...
- How it works...
- Parallelizing a LINQ query
- Getting ready
- How to do it...
- How it works...
- Tweaking the parameters of a PLINQ query
- Getting ready
- How to do it...
- How it works...
- Handling exceptions in a PLINQ query
- Getting ready
- How to do it...
- How it works...
- Managing data partitioning in a PLINQ query
- Getting ready
- How to do it...
- How it works...
- Creating a custom aggregator for a PLINQ query
- Getting ready
- How to do it...
- How it works...
- 8. Reactive Extensions
- Introduction
- Converting a collection to asynchronous Observable
- Getting ready
- How to do it...
- How it works...
- Writing custom Observable
- Getting ready
- How to do it...
- How it works...
- Using Subjects
- Getting ready
- How to do it...
- How it works...
- Creating an Observable object
- Getting ready
- How to do it...
- How it works...
- Using LINQ queries against the observable collection
- Getting ready
- How to do it...
- How it works...
- Creating asynchronous operations with Rx
- Getting ready
- How to do it...
- How it works...
- 9. Using Asynchronous I/O
- Introduction
- Working with files asynchronously
- Getting ready
- How to do it...
- How it works...
- Writing an asynchronous HTTP server and client
- Getting ready
- How to do it...
- How it works...
- Working with a database asynchronously
- Getting ready
- How to do it...
- How it works...
- Calling a WCF service asynchronously
- Getting ready
- How to do it...
- How it works...
- 10. Parallel Programming Patterns
- Introduction
- Implementing Lazy-evaluated shared states
- Getting ready
- How to do it...
- How it works...
- Implementing Parallel Pipeline with BlockingCollection
- Getting ready
- How to do it...
- How it works...
- Implementing Parallel Pipeline with TPL DataFlow
- Getting ready
- How to do it...
- How it works...
- Implementing Map/Reduce with PLINQ
- Getting ready
- How to do it...
- How it works...
- 11. There's More
- Introduction
- Using a timer in a Windows Store application
- Getting ready
- How to do it...
- How it works...
- Using WinRT from usual applications
- Getting ready
- How to do it...
- How it works...
- Using BackgroundTask in Windows Store applications
- Getting ready
- How to do it...
- How it works...
- Index
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.
File format: PDF
Copy-Protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (only limited: Kindle).
The file format PDF always displays a book page identically on any hardware. This makes PDF suitable for complex layouts such as those used in textbooks and reference books (images, tables, columns, footnotes). Unfortunately, on the small screens of e-readers or smartphones, PDFs are rather annoying, requiring too much scrolling.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our eBook Help page.