Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Category: C#

C#

C# LINQ Kills Performance in Hot Paths

- 06.01.26 - ErcanOPAK comment on C# LINQ Kills Performance in Hot Paths

Readable but slow. WhyAllocations and deferred execution. FixUse loops in critical sections.

Read More
C#

C# async void Causes Invisible Crashes

- 06.01.26 - ErcanOPAK comment on C# async void Causes Invisible Crashes

No stack trace. WhyExceptions cannot be awaited. FixAvoid async void except event handlers.

Read More
Asp.Net Core / C#

ASP.NET Core Requests Hang Randomly

- 06.01.26 - ErcanOPAK comment on ASP.NET Core Requests Hang Randomly

No exceptions thrown. WhyThread starvation due to sync-over-async. Fix await Task.Run(() => AsyncMethod()).ConfigureAwait(false);  

Read More
C#

Static State Causes Test Flakiness

- 05.01.26 - ErcanOPAK comment on Static State Causes Test Flakiness

Tests pass alone, fail together. WhyShared static state leaks between tests. Fix Avoid statics in business logic.

Read More
C#

List.ForEach Hides Exceptions

- 05.01.26 - ErcanOPAK comment on List.ForEach Hides Exceptions

Errors vanish. WhyExceptions thrown inside delegates are harder to trace. Fix Use explicit loops for critical logic.

Read More
C#

Task.Run Inside ASP.NET Core Hurts Scalability

- 05.01.26 - ErcanOPAK comment on Task.Run Inside ASP.NET Core Hurts Scalability

Seems async, kills throughput. WhyConsumes thread pool threads. Fix Use async APIs instead of offloading.

Read More
C#

IEnumerable Executes More Than Once

- 04.01.26 - ErcanOPAK comment on IEnumerable Executes More Than Once

Unexpected duplicate work. WhyDeferred execution. Fix var data = query.ToList();  

Read More
C#

Boxing Happens Without You Noticing

- 04.01.26 - ErcanOPAK comment on Boxing Happens Without You Noticing

Performance drops mysteriously. WhyInterfaces cause value types to box. Fix Use generics to avoid boxing.

Read More
C# / Development

async void Swallows Exceptions

- 04.01.26 - ErcanOPAK comment on async void Swallows Exceptions

Errors disappear. Whyasync void cannot be awaited. Fix async Task MethodAsync()  

Read More
Asp.Net Core / C#

ASP.NET Core Thread Pool Starves Under Load

- 04.01.26 - ErcanOPAK comment on ASP.NET Core Thread Pool Starves Under Load

Requests queue endlessly. WhyLong-running sync tasks block threads. Fix await Task.Run(LongRunningWork);  

Read More
C#

DateTime.Now Breaks Distributed Logic

- 03.01.26 | 03.01.26 - ErcanOPAK comment on DateTime.Now Breaks Distributed Logic

Same code, different results. WhyLocal time zones and daylight saving. Fix DateTimeOffset.UtcNow   πŸ”₯ Why DateTime.Now Breaks Distributed Logic (And What to Use Instead) Same code. Different results.If you’ve ever seen time-based logic randomly fail in production, DateTime.Now might be the silent culprit. In distributed systems, local time is a trap. 🚨 The Core Problem […]

Read More
C#

LINQ Looks Clean but Allocates Heavily

- 03.01.26 - ErcanOPAK comment on LINQ Looks Clean but Allocates Heavily

Readable code, hidden cost. WhyMultiple enumerations. Fix var list = items.ToList();  

Read More
C#

Async Methods Still Block the Thread Pool

- 03.01.26 - ErcanOPAK comment on Async Methods Still Block the Thread Pool

Looks async, behaves sync. WhyCPU-bound work inside async methods. Fix await Task.Run(Compute);  

Read More
Asp.Net Core / C#

ASP.NET Core Memory Usage Keeps Growing

- 03.01.26 - ErcanOPAK comment on ASP.NET Core Memory Usage Keeps Growing

GC runs, memory stays high. WhyObject pooling misused or ignored. Fix services.AddPooledDbContextFactory<AppDbContext>();  

Read More
C#

Exceptions Used for Control Flow

- 03.01.26 - ErcanOPAK comment on Exceptions Used for Control Flow

Works until scale. WhyExceptions are expensive. Fix if (!TryParse(…)) return;  

Read More
C#

Events Cause Memory Leaks

- 03.01.26 - ErcanOPAK comment on Events Cause Memory Leaks

Even in managed code. WhyUnsubscribed event handlers. FixAlways unsubscribe or use weak events.

Read More
C#

Structs Can Be Slower Than Classes

- 03.01.26 - ErcanOPAK comment on Structs Can Be Slower Than Classes

Surprising but true. WhyLarge structs copied by value. Fix void Process(in MyStruct data)  

Read More
Asp.Net Core / C#

ASP.NET Core Requests Hang Under Load

- 03.01.26 - ErcanOPAK comment on ASP.NET Core Requests Hang Under Load

CPU low, threads exhausted. WhyBlocking calls inside async pipeline. Fix await SomeAsyncMethod();  

Read More
C#

Exceptions Used for Flow Control

- 02.01.26 - ErcanOPAK comment on Exceptions Used for Flow Control

Works… until scale. WhyExceptions are expensive. Fix Use Try-patterns instead.

Read More
C#

LINQ Causing Hidden Allocations

- 02.01.26 - ErcanOPAK comment on LINQ Causing Hidden Allocations

Clean code, slow runtime. WhyDeferred execution + boxing. Fix Materialize once when needed.

Read More
C#

C# Async Methods Still Block Threads

- 02.01.26 - ErcanOPAK comment on C# Async Methods Still Block Threads

Looks async, isn’t. WhyCPU-bound work inside async. Fix Offload CPU work explicitly. await Task.Run(() => HeavyCalculation());  

Read More
C#

Events Can Cause Memory Leaks

- 01.01.26 - ErcanOPAK comment on Events Can Cause Memory Leaks

Even in managed code. Why it happensUnsubscribed event handlers. FixAlways unsubscribe or use weak events.

Read More
C#

DateTime.Now Can Break Distributed Systems

- 01.01.26 - ErcanOPAK comment on DateTime.Now Can Break Distributed Systems

Time is harder than it looks. Why it happensTime zones + daylight saving. FixUse DateTimeOffset.UtcNow.

Read More
C#

C# Value Types Copied More Than You Think

- 01.01.26 - ErcanOPAK comment on C# Value Types Copied More Than You Think

Structs aren’t always faster. Why it happensLarge structs passed by value. FixUse in parameters.

Read More
C#

C# β€” GC.Collect() Hurts More Than It Helps

- 31.12.25 - ErcanOPAK comment on C# β€” GC.Collect() Hurts More Than It Helps

Manual GC kills performance. Rule Let the runtime decide.

Read More
C#

C# β€” async void Event Handlers Swallow Exceptions

- 31.12.25 - ErcanOPAK comment on C# β€” async void Event Handlers Swallow Exceptions

Crashes disappear silently. Fix Wrap logic with try/catch and logging.

Read More
C#

C# β€” Equals Without Operator Overload Is Inconsistent

- 31.12.25 - ErcanOPAK comment on C# β€” Equals Without Operator Overload Is Inconsistent

== and Equals() behave differently. Fix Override both consistently.

Read More
C#

C# β€” Stopwatch Is More Accurate Than DateTime

- 30.12.25 - ErcanOPAK comment on C# β€” Stopwatch Is More Accurate Than DateTime

Measuring performance with DateTime lies. βœ… Fix Stopwatch sw = Stopwatch.StartNew();  

Read More
C#

C# β€” async Lambdas Capture Variables Unexpectedly

- 30.12.25 - ErcanOPAK comment on C# β€” async Lambdas Capture Variables Unexpectedly

Loop variables are captured by reference. ❌ Bug Perfectly compiled, logically broken code. βœ… Fix Create a local copy inside the loop.

Read More
C#

C# β€” string.Equals() Without ComparisonType Is a Bug

- 30.12.25 | 30.12.25 - ErcanOPAK comment on C# β€” string.Equals() Without ComparisonType Is a Bug

Default comparison is culture-sensitive. string.Equals(a, b) ❌ Risk Unexpected results in different locales. βœ… Fix string.Equals(a, b, StringComparison.Ordinal)  

Read More
Page 7 of 14
Β« Previous 1 2 3 4 5 6 7 8 9 10 11 12 … 14 Next Β»

Posts navigation

Older posts
Newer posts
April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Mar    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (753)
  • Add Constraint to SQL Table to ensure email contains @ (578)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (564)
  • Average of all values in a column that are not zero in SQL (531)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (489)
  • Find numbers with more than two decimal places in SQL (447)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries
  • SQL: Use Window Functions for Advanced Analytical Queries
  • .NET Core: Use Background Services for Long-Running Tasks
  • .NET Core: Use Minimal APIs for Lightweight HTTP Services
  • Git: Use Cherry-Pick to Apply Specific Commits Across Branches
  • Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (753)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com