Book Image

Improving your C# Skills

By : Ovais Mehboob Ahmed Khan, John Callaway, Clayton Hunt, Rod Stephens
Book Image

Improving your C# Skills

By: Ovais Mehboob Ahmed Khan, John Callaway, Clayton Hunt, Rod Stephens

Overview of this book

This Learning Path shows you how to create high performing applications and solve programming challenges using a wide range of C# features. You’ll begin by learning how to identify the bottlenecks in writing programs, highlight common performance pitfalls, and apply strategies to detect and resolve these issues early. You'll also study the importance of micro-services architecture for building fast applications and implementing resiliency and security in .NET Core. Then, you'll study the importance of defining and testing boundaries, abstracting away third-party code, and working with different types of test double, such as spies, mocks, and fakes. In addition to describing programming trade-offs, this Learning Path will also help you build a useful toolkit of techniques, including value caching, statistical analysis, and geometric algorithms. This Learning Path includes content from the following Packt products: • C# 7 and .NET Core 2.0 High Performance by Ovais Mehboob Ahmed Khan • Practical Test-Driven Development using C# 7 by John Callaway, Clayton Hunt • The Modern C# Challenge by Rod Stephens
Table of Contents (26 chapters)
Title Page
Copyright and Credits
About Packt
What to Know Before Getting Started
Files and Directories
Advanced C# and .NET Features

Multithreading in .NET Core

There are many benefits in using multithreading in CPU and/or I/O-bound applications. It is often used for long-running processes that have a longer or infinite lifetime, working as background tasks, keeping the main thread available in order to manage or handle user requests. However, unnecessary use may completely degrade the application's performance. There are cases where creating too many threads is not a good architecture practice.

Here are some examples where multithreading is a good fit:

  • I/O operations
  • Running long-running background tasks
  • Database operations
  • Communicating over a network

Multithreading caveats

Although there are many benefits to multithreading, there are some caveats that need to be thoroughly addressed when writing multithreaded applications. If the machine is a single or two-core machine and the application is creating lots of threads, the context switching between these threads will slow the performance:

The preceding diagram depicts the program...