Book Image

High-Performance Programming in C# and .NET

By : Jason Alls
Book Image

High-Performance Programming in C# and .NET

By: Jason Alls

Overview of this book

Writing high-performance code while building an application is crucial, and over the years, Microsoft has focused on delivering various performance-related improvements within the .NET ecosystem. This book will help you understand the aspects involved in designing responsive, resilient, and high-performance applications with the new version of C# and .NET. You will start by understanding the foundation of high-performance code and the latest performance-related improvements in C# 10.0 and .NET 6. Next, you’ll learn how to use tracing and diagnostics to track down performance issues and the cause of memory leaks. The chapters that follow then show you how to enhance the performance of your networked applications and various ways to improve directory tasks, file tasks, and more. Later, you’ll go on to improve data querying performance and write responsive user interfaces. You’ll also discover how you can use cloud providers such as Microsoft Azure to build scalable distributed solutions. Finally, you’ll explore various ways to process code synchronously, asynchronously, and in parallel to reduce the time it takes to process a series of tasks. By the end of this C# programming book, you’ll have the confidence you need to build highly resilient, high-performance applications that meet your customer's demands.
Table of Contents (22 chapters)
1
Part 1: High-Performance Code Foundation
7
Part 2: Writing High-Performance Code
16
Part 3: Threading and Concurrency

Chapter 1: Introducing C# 10.0 and .NET 6

Microsoft .NET 6 and C# 10.0 are the latest incarnations of the .NET platform and C# programming language. They bring many performance enhancements to the C# and .NET programmer community. We will start this book with an overview of the new versions of C# and .NET.

In this chapter, you will start by downloading, restoring, building, and testing the latest version of the .NET compiler called Roslyn. Then, you will review what's new in .NET 6, including the areas where performance has been greatly enhanced. Then, you will review what's new in C# 10.0 by looking at some code examples that demonstrate these features.

In the Native compilation section, you will build a project and run it as an MSIL project with multiple binaries, then compile and run it as a single native binary. Finally, you will learn how to improve the performance of Windows Store applications and ASP.NET websites.

In this chapter, we will cover the following topics:

  • Overview of .NET 6: In this section, we will cover, at a high level, what's new in .NET 6. You will learn about the various performance improvements that will be part of .NET 6.
  • Overview of C# 10.0: Having learned how to obtain the latest Roslyn code in the Technical requirements section, in this section, you will learn about the various features that will be part of C# 10.0. This will include code examples.
  • Native compilation: In this section, you will learn how to compile a .NET Core application into a single native executable. You will write a simple console application that recursively converts audio files from one format into another.
  • Improving Windows Store performance: This is a brief section that provides standard guidelines for improving the performance of applications that target the Windows Store.
  • Improving ASP.NET performance: This is a brief section that provides some standard guidelines for improving ASP.NET applications.

By the end of this chapter, you will have the following skills:

  • You will understand what's new in Microsoft .NET 6.
  • You will be able to apply the new C# 10.0 code features within your source code.
  • You will be able to compile your source code to native assemblies (also known as binaries).
  • You will know what, how, and where to look for information on improving the performance of applications that target the Windows Store.
  • You will know what, how, and where to look for information on improving the performance of ASP.NET applications.

Let's begin this chapter by looking at Microsoft .NET 6.