C# 2008 and 2005 Threaded Programming: Beginner's Guide

More Information
Learn
  • Transform single-threaded algorithms to multithreaded scalable jobs by using object-oriented capabilities create an independent thread with an asynchronous execution by using a delegate to update the UI
  • Achieve responsive user interface using synchronous and asynchronous delegates to dispatch changes to the UI thread
  • Specify the degree of parallelism desired for determining the number of threads that the query must use to achieve better performance
  • Create applications that use the full power of the processors using parallel programming techniques
  • Develop applications to create background threads using the BackgroundWorker component
  • Learn debugging techniques to find solutions to multithreaded application problems


Chapter 1: Taking Advantage of Multiprocessing and Multiple Cores
Mono-processor systems: The old gladiators
Single core: Only one warrior to fight against everybody
The performance waterfall
Multi-processor systems: Many warriors to win a battle
Estimating performance improvements
Avoiding bottlenecks
Taking advantage of multiple execution cores
Scalability
Load balancing: Keeping everybody happy
Operating systems and virtual machines
Parallelism is here to stay
Code patterns learned in this chapter
Exercises

Chapter 2: Processes and Threads
What is a process?
What is a thread?
Multiple threads in servers
Multiple threads in clients
Code patterns learned in this chapter
Exercises

Chapter 3: BackgroundWorker in action for beginners
RTC: Rapid thread creation
Defining the work to be done
Asynchronous execution
Synchronous execution
Showing the progress
Canceling the job
Working with multiple BackgroundWorker
BackgroundWorker vs. Timer
BackgroundWorker creation on the fly
Code patterns learned in this chapter
Exercises

Chapter 4: Thread Class—Practical Multithreading in Applications
Creating threads with the Thread class
Sharing data between threads
Passing parameters to threads
Code patterns learned in this chapter
Exercises

Chapter 5: Simple Debugging Techniques with Multithreading
Watching multiple threads
Debugging multithreaded applications as single-threaded applications
Showing partial results in multi threaded code
Code patterns learned in this chapter
Exercises

Chapter 6: Understanding threads’ control with patterns
Starting, Joining, Pausing and Restarting threads
Understanding the pixels' color compositions
Creating independent blocks of concurrent code
Using flags to enhance control over concurrent threads
Testing results with Performance Monitor and Process Explorer
Using the AutoResetEvent class to handle signals between threads
Using the WaitHandle class to check for signals
Code patterns learned in this chapter
Exercises

Chapter 7: Dynamically Splitting Jobs into Pieces—Avoiding Problems
Running split jobs many times
Using classes, methods, procedures, and functions with multithreading capabilities
Understanding the garbage collector with multi threading
Controlling the system garbage collector with the GC class
Avoiding garbage collection problems
Avoiding inefficient processing usage problems
Retrieving the total memory thought to be allocated
Generalizing the algorithms for segmentation with classes
Code patterns learned in this chapter
Exercises

Chapter 8: Simplifying Parallelism Complexity
Specializing the algorithms for segmentation with classes
Defining the class to instantiate
Creating simple constructors
Programming the results collection method
Optimizing and encapsulati ng parallel algorithms
Achieving thread affinity
Avoiding locks and many synchronization nightmares
Code patterns learned in this chapter
Exercises

Chapter 9: Working with Parallelized Input/Output and Data Access
Queuing threads with I/O operati ons
Avoiding Input/Output bott lenecks
Using concurrent streams
Controlling excepti ons in threads
Using a pool of threads with the ThreadPool class
Managing the thread queue in the pool
Converting single-threaded tasks to a multithreaded pool
Encapsulating scalability
Thread affinity in a pool of threads
Parallelizing database access
Code patterns learned in this chapter
Exercises

Chapter 10: Parallelizing and Concurrently Updating the User Interface
Updating the UI from independent threads
Creating delegates to make cross-thread calls
Reporting progress to the UI from independent threads
Creating a delegate without parameters
Invoking a delegate asynchronously to avoid performance degradation
Code patterns learned in this chapter
Exercises

Chapter 11: Coding with .NET Parallel Extensions
Parallelizing loops using .NET extensions
Counting and showing blobs while avoiding side effects
Using a parallelized ForEach loop
Coding with delegates in parallelized loops
Working with a concurrent queue
Controlling excepti ons in parallelized loops
Combining delegates with a BackgroundWorker
Retrieving elements from a concurrent queue in a producer-consumer scheme
Creating an asynchronous task combined with a synchronous parallel loop
Using lambda expressions to simplify the code
Parallelizing loops with ranges
Parallelizing queries
Parallelizing LINQ queries with PLINQ
Specifying the degree of parallelism for PLINQ
Parallelizing stati stics and multiple queries
Code patterns learned in this chapter
Exercises

Chapter 12: Developing a Completely Parallelized Application
Joining many different parallelized pieces into a complete application
Running code out of the UI thread
Blocking the UI—Forbidden with multi threading code
Combining threads with a pool of threads and the UI thread
Creating threads inside other threads
Multi ple windows and one UI thread for all of them
Rationalizing multi threaded code
Code patterns learned in this chapter
Exercises

About

Most modern machines have dual core processors. This means that multitasking is built right into your computer's hardware. Using both cores means your applications can process data faster and be more responsive to users. But to fully exploit this in your applications, you need to write multithreading code, which means learning some challenging new concepts.

This book will guide you through everything you need to start writing multithreaded C# applications. You will see how to use processes and threads in C#, .NET Framework features for concurrent programming, sharing memory space between threads, and much more. The book is full of practical, interesting examples and working code.

This book begins with the fundamental concepts such as processes, threads, mono-processor systems, multi-processor systems. As the book progresses, the readers get a clear understanding of starting, joining, pausing and restarting threads. The readers get a better understanding of the simple techniques associated with parallelism. There are short exercises at the end of every chapter for the readers to perform.

The book also includes several practical parallelism algorithms and data structures used for illustration, and best practices and practical topics like debugging and performance.

Features
  • Develop applications that run several tasks simultaneously to achieve greater performance, scalability, and responsiveness in your applications
  • Build and run well-designed and scalable applications with C# parallel programming.
  • In-depth practical approach to help you become better and faster at managing different processes and threads
  • Optimized techniques on parallellized processes for advanced concepts
  • Packed with hands-on-examples and clear explanations for better understanding
Page Count 416
Course Length 12 hours 28 minutes
ISBN 9781847197108
Date Of Publication 28 Jan 2009

Authors

Gaston C. Hillar

Gaston C. Hillar is Italian and has been working with computers since he was 8 years old. Gaston has a Bachelor's degree in computer science (graduated with honors) and an MBA.

_x000D_

Currently, Gaston is an independent IT consultant and a freelance author who is always looking for new adventures anywhere in the world.

_x000D_

He was a senior contributing editor at Dr. Dobb's, and has written more than a hundred articles on software development topics. He has received the prestigious Intel® Black Belt Software Developer award eight times. He has written many articles about Java for Oracle Java Magazine.

_x000D_

Gaston was also a former Microsoft MVP in technical computing. He lives with his wife, Vanesa, and his two sons, Kevin and Brandon.