Skip to main content

Posts

Showing posts with the label objects

Fixing High CPU Usage in .NET Core using Parallelism

  We will fix problem occurs due to incorrect use Parallelism in .NET Core To increase application performance sometimes we use process task or work extensively in Parallel and that may lead performance issue. When we do code, we should understand our requirement very carefully along with hardware resources those we have. We should code like that there should be less CPU usage and server should work without issues. In .NET Core, when you’re using parallelism (like Parallel.For, Task.WhenAll, or Task.Run), you might encounter performance issues if the number of concurrent threads or tasks exceeds what your system can efficiently handle. A common issue is high CPU usage or resource contention, which can degrade overall performance, cause excessive context switching, and even lead to thread starvation or deadlocks. Non members can access from here Effective Parallelism Strategies to Mitigate High CPU Usage in .NET Core We will fix problem occurs due to incorrect use Parallelism in .NE...

Builder Pattern in C#: Practical Implementation and Examples

  This pattern can be ideal approach to create complex objects The Builder pattern is a creational design pattern that is used to construct complex objects step by step. It allows you to create different representations of an object using the same construction process. Let’s first understand the problems that exist without using this pattern. Complex Constructor with Many Parameters When creating objects that require many parameters, constructors can become lengthy and hard to read. public class House { public House ( int walls, int doors, int windows, bool hasGarage, bool hasSwimmingPool, bool hasStatues, bool hasGarden) { // Initialization } } There are many problems if constructor have too many parameters i) Each time we need to pass n numbers of parameters at time of object creations ii) we need to update constructor if we need to pass one more parameter so such constructor difficult to manage 2.  Constructor Overload Explosion Sometimes we ne...