High-Performance Programming in C# and .NET: Understand the nuts and bolts of developing robust, faster, and resilient applications in C# 10.0 and .NET 6
Book information
Description
Enhance your applications' performance using best practices for benchmarking, application profiling, asynchronous programming, designing responsive UIs, gRPC communication, and distributed applications Key FeaturesMake the best use of performance enhancements in C# 10.0 and .NET 6Boost application performance by identifying hardware bottlenecks and common performance pitfallsGet to grips with best practices and techniques for improving the scalability of distributed systemsBook Description 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. What you will learnUse correct types and collections to enhance application performanceProfile, benchmark, and identify performance issues with the codebaseExplore how to best perform queries on LINQ to improve an application's performanceEffectively utilize a number of CPUs and cores through asynchronous programmingBuild responsive user interfaces with WinForms, WPF, MAUI, and WinUIBenchmark ADO.NET, Entity Framework Core, and Dapper for data accessImplement CQRS and event sourcing and build and deploy microservicesWho this book is for This book is for software engineers, professional software developers, performance engineers, and application profilers looking to improve the speed of their code or take their skills to the next level to gain a competitive advantage. You should be a proficient C# programmer who can already put the language to good use and is also comfortable using Microsoft Visual Studio 2022. Table of ContentsIntroducing C# 10.0 and .NET 6Implementing C# InteroperabilityPredefined Data Types and Memory AllocationsMemory ManagementApplication Profiling and TracingThe .NET CollectionsLINQ PerformanceFile and Stream I/OEnhancing the Performance of Networked ApplicationsSetting Up Our Database ProjectBenchmarking Relational Data Access FrameworksResponsive User InterfacesDistributed SystemsMulti-Threaded ProgrammingParallel ProgrammingAsynchronous Programming Cover Title Copyright and Credits Table of Contents Part 1: High-Performance Code Foundation Chapter 1: Introducing C# 10.0 and .NET 6 Technical requirements Obtaining and building the latest Roslyn compiler from the source code Overview of Microsoft .NET 6 Moving to one unified platform Garbage collection Just-In-Time compiler Text-based processing Threading and asynchronous operations Collections and LINQ Networking and Blazor New performance-based APIs and analyzers Overview of C# 10.0 Writing top-level programs Using init-only properties Using records Using the new pattern matching features Using new expressions with targeted types Using covariant returns Native compilation Performing native compilation of .NET Core applications Improving Windows Store performance Improving ASP.NET performance Summary Questions and exercises Further reading Chapter 2: Implementing C# Interoperability Technical requirements Using Platform Invocation (P/Invoke) Using unsafe and fixed code Exposing static entry points using P/Invoke Interacting with Python code Performing Component Object Model (COM) interoperability Reading data from an Excel spreadsheet Creating an Excel add-in Safely disposing of unmanaged code Summary Questions Further reading Chapter 3: Predefined Data Types and Memory Allocations Technical requirements Understanding the predefined .NET data types Understanding the predefined value types in C# Understanding the predefined reference types in C# Understanding static types Understanding the various types of memory used in C# The stack The heap Building a stack versus building a heap (example project) Choosing between a struct and a class Passing by value and passing by reference Building a pass-by-reference example program Boxing and unboxing Performing boxing Performing unboxing Summary Questions Further reading Chapter 4: Memory Management Technical requirements Object generations and avoiding memory issues Understanding long and short weak references Finalization Using finalization Implementing the IDisposable pattern Preventing memory leaks Understanding the dangers of using Marshal.ReleaseComObject How using events can be a source of memory leaks Summary Questions Further reading Chapter 5: Application Profiling and Tracing Technical requirements Understanding code metrics Application metrics Assembly metrics Namespace metrics Type metrics Method metrics Field metrics Performing static code analysis Generating and viewing memory dumps Viewing loaded modules Debugging your applications Using tracing and diagnostics tools Using the Visual Studio 2022 Performance Profiler Using JetBrains dotMemory Using JetBrains dotTrace Installing and using dotnet-counters Collecting data and saving it to a file for post-analysis Listing .NET processes that can be monitored Listing the available list of well-known .NET counters Monitoring a .NET process Tracking down and fixing a memory leak with dotMemory Finding the cause of a UI freeze with dotTrace Optimizing application performance and memory traffic with dotTrace Summary Questions Further reading Part 2: Writing High-Performance Code Chapter 6: .NET Collections Technical requirements Understanding the different collection offerings The System.Collections namespace The System.Collections.Generic namespace The System.Collections.Concurrent namespace The System.Collections.Specialized namespace Creating custom collections Understanding Big O notation Choosing the right collection Setting up our sample database Deciding between interfaces and concrete classes Deciding between using arrays or collections Accessing objects using indexers Comparing IEnumerable and IEnumerator Database query performance Exploring the yield keyword Learning the difference between concurrency and parallelism Learning the difference between Equals() and == Summary Questions Further reading Chapter 7: LINQ Performance Technical requirements Setting up a sample database Setting up our in-memory sample data Database query performance Getting the last value of a collection Avoid using the let keyword in LINQ queries Increasing Group By performance in LINQ queries Filtering lists Understanding closures Summary Questions Further reading Chapter 8: File and Stream I/O Technical requirements Understanding the various Windows file path formats Removing the maximum path length limitation using the registry Removing the maximum path length limitation using the group policy Considering improved I/O performance Moving files Calculating directory sizes Accessing files asynchronously Writing text to a file asynchronously Handling I/O operation exceptions Performing memory tasks efficiently Understanding local storage tasks Summary Questions Further reading Chapter 9: Enhancing the Performance of Networked Applications Technical requirements Understanding the network layers and protocols The TCP/IP model Writing an example email application with the TCP/IP model Improving web-based network traffic Recording your web-applications performance using Microsoft Edge High-performance communication using gRPC Programming a simple gRPC client/server application Programming a simple gRPC Blazor application The blank solution Optimizing internet resources Using pipelines for content streaming Writing and running a TCP server console application Writing and running a TCP client console application Caching resources in memory Summary Questions Further reading Chapter 10: Setting Up Our Database Project Technical requirements Setting up our database Setting up our database access project Writing the Properties class Writing the DatabaseSettings class Writing the SecretsManager Writing the Product class Writing the SqlCommandModel class Writing the SqlCommandParameterModel class Writing the AdoDotNet class Writing the EntityFrameworkCoreData class Writing the DapperDotNet class Summary Further reading Chapter 11: Benchmarking Relational Data Access Frameworks Technical requirements Benchmarking data insertion methods Benchmarking data selection methods Benchmarking data editing methods Benchmarking data deletion methods The benchmarking results and their analysis Summary Questions Further reading Chapter 12: Responsive User Interfaces Technical requirements Building a responsive UI with WinForms Enabling DPI awareness and long file path awareness Adding a splash screen that updates with loading progress Adding the increment count button and label Adding a table with paged data Running long-running tasks in the background Building a responsive UI with WPF Building a responsive UI with ASP.NET Implementing memory caching Implementing distributed caching Using AJAX to update part of the currently displayed page Implementing WebSockets Implementing a real-time chat application using SignalR Building responsive UIs with .NET MAUI Layouts Accessibility BlazorWebView Building a responsive UI with MAUI Building a responsive UI with WinUI 3 Summary Questions Further reading Chapter 13: Distributed Systems Technical requirements Implementing the CQRS design pattern Implementing event sourcing Event sourcing example project Using Microsoft Azure for distributed systems Azure Functions Durable Azure Functions Containers and serverless Managing your cloud infrastructure with Pulumi Performance considerations for distributed computing Summary Questions Further reading Part 3: Threading and Concurrency Chapter 14: Multi-Threaded Programming Technical requirements Understanding threads and threading Creating threads and using parameters Pausing and interrupting threads Destroying and canceling threads Scheduling threads Thread synchronization and locking Summary Questions Further reading Chapter 15: Parallel Programming Technical requirements Using the Task Parallel Library (TPL) Using Parallel LINQ (PLINQ) Programming parallel data structures Benchmarking with BenchmarkDotNet Using lambda expressions with TPL and LINQ Parallel debugging and profiling tools The Parallel Stacks window The Tasks window The Concurrency Visualizer Summary Questions Further reading Chapter 16: Asynchronous Programming Technical requirements Understanding the TAP model Naming, parameters, and return types Initiating asynchronous operations Exceptions Optional cancellation Optional Progress Reporting async, await, and Task Benchmarking GetAwaiter.GetResult(), .Result, and .Wait for both Task and ValueTask Using async, await, and WhenAll Canceling asynchronous operations Writing files asynchronously Reading files asynchronously Summary Questions Further reading Assessments Chapter 1, Introducing C# 10.0 and .NET 6 Chapter 2, Implementing C# Interoperability Chapter 3, Predefined Data Types and Memory Allocations Chapter 4, Memory Management Chapter 5, Application Profiling and Tracing Chapter 6, The .NET Collections Chapter 7, LINQ Performance Chapter 8, File and Stream I/O Chapter 9, Enhancing the Performance of Networked Applications Chapter 10, Setting Up Our Database Project Chapter 11, Benchmarking Relational Data Access Frameworks Chapter 12, Responsive User Interfaces Chapter 13, Distributed Systems Chapter 14, Multi-Threaded Programming Chapter 15, Parallel Programming Chapter 16, Asynchronous Programming Index
Similar books
High-Performance Programming in C# and .NET: Understand the nuts and bolts of developing robust, faster, and resilient applications in C# 10.0 and .NET 6
2022 · PDF
Clean Code with C#: Refactor your legacy C# code base and improve application performance using best practices
2023 · PDF
High-Performance Programming in C# and .NET: Understand the nuts and bolts of developing robust, faster, and resilient applications in C# 10.0 and .NET 6
2022 · EPUB
Clean Code in C#: Refactor your legacy C# code base and improve application performance by applying best practices
2020 · PDF
Clean Code in C#: Refactor your legacy C# code base and improve application performance by applying best practices
2020 · EPUB
MySQL® Notes for Professionals book
2018 · PDF
MrExcel 2022: Boosting Excel
2022 · PDF
MrExcel 2022: Boosting Excel
2022 · PDF