Summary
In this chapter, we discussed some best practices to follow when working with managed threads in C# and .NET. We started by creating some examples of how to manage and process static data in a multithreaded application. The examples illustrated how to leverage locks, work with singletons, and how static constructors can impact performance when working with static data. Next, we explored some techniques for avoiding deadlocks and race conditions. Both pitfalls can be avoided if you design your algorithms to minimize the need for locking. Finally, we looked at some features of .NET that can adjust the limits of several parallel and thread pool operations.
At this point, you are well prepared to start using managed threads responsibly in your .NET projects. For some further reading on best practices with managed threading, you can check out some recommendations on Microsoft Docs: https://docs.microsoft.com/en-us/dotnet/standard/threading/managed-threading-best-practices.
...