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: Asp.Net Core

Asp.Net Core / C#

The Real Cost of IHostedService Misuse

- 29.01.26 - ErcanOPAK comment on The Real Cost of IHostedService Misuse

Background services look harmless… until production. Common mistake Long-running loops No cancellation handling Blocking delays Correct pattern while (!stoppingToken.IsCancellationRequested) { await DoWorkAsync(stoppingToken); await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken); } Why Graceful shutdowns save data and prevent zombie processes.

Read More
Asp.Net Core / C#

Why Async Controllers Still Block Threads

- 29.01.26 - ErcanOPAK comment on Why Async Controllers Still Block Threads

Async ≠ non-blocking. The trap public async Task<IActionResult> Get() { var data = _service.GetDataAsync().Result; return Ok(data); } Why it blocks .Result blocks the request thread Can cause thread starvation under load Fix var data = await _service.GetDataAsync();  

Read More
Asp.Net Core

Environment-Specific Config Overrides

- 28.01.26 - ErcanOPAK comment on Environment-Specific Config Overrides

Why it mattersAvoids prod accidents caused by wrong configs.

Read More
Asp.Net Core / C#

Minimal APIs with Validation

- 28.01.26 - ErcanOPAK comment on Minimal APIs with Validation

app.MapPost(“/users”, (User u) => Results.Ok()); Why it mattersLess ceremony, same power.

Read More
Asp.Net Core / C#

Use ProblemDetails for API Errors

- 27.01.26 - ErcanOPAK comment on Use ProblemDetails for API Errors

return Results.Problem(“Invalid input”); Why it mattersStandardized error responses = better clients.

Read More
Asp.Net Core / C#

Background Tasks with IHostedService

- 27.01.26 - ErcanOPAK comment on Background Tasks with IHostedService

public class Worker : BackgroundService { protected override Task ExecuteAsync(CancellationToken ct) => Task.CompletedTask; } Why it mattersClean background jobs without hacks.

Read More
Asp.Net Core / C#

Use MapGroup for Clean Endpoints

- 26.01.26 - ErcanOPAK comment on Use MapGroup for Clean Endpoints

app.MapGroup(“/api/users”) .MapGet(“/”, GetUsers); Why it mattersBetter structure without controllers.

Read More
Asp.Net Core / C#

Why Minimal APIs Improve Cold Start

- 26.01.26 - ErcanOPAK comment on Why Minimal APIs Improve Cold Start

app.MapGet(“/ping”, () => “pong”); Why it mattersLess middleware, faster startup.

Read More
Asp.Net Core / C#

Use IHttpClientFactory or Face Socket Exhaustion

- 25.01.26 - ErcanOPAK comment on Use IHttpClientFactory or Face Socket Exhaustion

Creating HttpClient per request is a silent killer. services.AddHttpClient(); Why this mattersConnection pooling prevents random production outages.

Read More
Asp.Net Core / C#

Why BackgroundService Beats Task.Run in APIs

- 25.01.26 - ErcanOPAK comment on Why BackgroundService Beats Task.Run in APIs

Fire-and-forget tasks die with requests. public class Worker : BackgroundService { protected override async Task ExecuteAsync(CancellationToken ct) { while (!ct.IsCancellationRequested) await DoWorkAsync(ct); } } Why this mattersHosted services respect app lifetime and graceful shutdown.

Read More
Asp.Net Core / C#

Use IOptionsSnapshot to Fix Config Reload Issues

- 24.01.26 - ErcanOPAK comment on Use IOptionsSnapshot to Fix Config Reload Issues

Reading config directly causes stale values. public MyService(IOptionsSnapshot<MyConfig> cfg) { _cfg = cfg.Value; } Why this mattersSupports per-request refresh in scoped services.

Read More
Asp.Net Core / C#

Why Async Controllers Improve Throughput (Not Speed)

- 24.01.26 - ErcanOPAK comment on Why Async Controllers Improve Throughput (Not Speed)

Async doesn’t make code faster — it makes servers scalable. public async Task<IActionResult> Get() { var data = await repo.GetAsync(); return Ok(data); } Why this mattersThreads are freed while waiting → more concurrent requests.

Read More
Asp.Net Core / C#

Why IAsyncEnumerable Is a Game-Changer for Data Streaming APIs

- 24.01.26 - ErcanOPAK comment on Why IAsyncEnumerable Is a Game-Changer for Data Streaming APIs

Returning large datasets blocks memory.Streaming them changes the entire performance profile. public async IAsyncEnumerable<int> StreamNumbers() { for (int i = 0; i < 1000; i++) { await Task.Delay(10); yield return i; } } Why it works Consumers process data as it arrives Lower memory footprint Faster perceived response times Perfect for: Reporting APIs Log streaming […]

Read More
Asp.Net Core / C#

Stop Wasting RAM: The Art of Zero-Allocation C#

- 23.01.26 - ErcanOPAK comment on Stop Wasting RAM: The Art of Zero-Allocation C#

How to achieve extreme performance in .NET 9 by mastering Span<T>, Memory<T>, and the Garbage Collector. In the world of cloud-native development, Memory is Money. Every byte you allocate on the Managed Heap is a debt that the Garbage Collector (GC) must eventually collect. The biggest bottleneck in high-throughput .NET applications isn’t typically the CPU’s […]

Read More
Asp.Net Core / C#

Is Your Clean Architecture Actually a “Dirty” Mess?

- 23.01.26 - ErcanOPAK comment on Is Your Clean Architecture Actually a “Dirty” Mess?

Why modern .NET 9 systems are moving away from rigid layers and embracing the “Vertical Slice” revolution. For the past decade, Clean Architecture (or Onion Architecture) has been the gold standard for .NET developers. We’ve been told to separate our concerns into layers: Domain, Application, Infrastructure, and Web. But as projects grow, we often find […]

Read More
Asp.Net Core / C#

The Most Expensive Mistake C# Developers Still Make in 2026

- 23.01.26 | 23.01.26 - ErcanOPAK comment on The Most Expensive Mistake C# Developers Still Make in 2026

How a single line of Task.Run can turn your high-performance C# application into a production time bomb. For years, C# has been marketed as a “safe” and “high-level” language. Garbage collection, async/await, dependency injection — all designed to protect developers from low-level mistakes. And yet… Some of the most expensive production failures I’ve seen in […]

Read More
Asp.Net Core

.NET Core Logs Disappear in Production

- 23.01.26 - ErcanOPAK comment on .NET Core Logs Disappear in Production

Local logs OK, prod empty. Why it happensWrong logging provider configuration. Why it mattersNo observability. Vital fix Explicitly configure providers.

Read More
Asp.Net Core

ASP.NET Core APIs Hang Under Load

- 23.01.26 - ErcanOPAK comment on ASP.NET Core APIs Hang Under Load

CPU low, requests hang. Why it happensThread pool starvation. Why it mattersThroughput collapses. Vital fix Avoid blocking calls in async paths.

Read More
Asp.Net Core

.NET Core Background Services Block Shutdown

- 22.01.26 - ErcanOPAK comment on .NET Core Background Services Block Shutdown

App hangs on exit. Why it happensNo cancellation handling. Why it mattersContainers fail to stop. Smart fixAlways pass CancellationToken.

Read More
Asp.Net Core

ASP.NET Core APIs Spike Memory Suddenly

- 22.01.26 - ErcanOPAK comment on ASP.NET Core APIs Spike Memory Suddenly

No traffic spike, memory spike. Why it happensObject pooling misuse. Why it mattersUnexpected restarts. Smart fixAvoid pooling large objects.

Read More
Asp.Net Core

.NET Core Logging Impacts Performance

- 21.01.26 - ErcanOPAK comment on .NET Core Logging Impacts Performance

Verbose logs slow everything. Why it happensSynchronous logging sinks. Why it mattersThroughput drops silently. Smart fixUse async logging providers.

Read More
Asp.Net Core / C#

ASP.NET Core Startup Is Slow

- 21.01.26 - ErcanOPAK comment on ASP.NET Core Startup Is Slow

Cold start hurts APIs. Why it happensHeavy dependency injection setup. Why it mattersFirst-request latency. Smart fixLazy-load expensive services. Lazy<MyService>  

Read More
Asp.Net Core / C#

.NET Core APIs Feel Slow Under Load

- 18.01.26 - ErcanOPAK comment on .NET Core APIs Feel Slow Under Load

Low traffic, bad response. WhySynchronous IO usage. TipPrefer async methods. await stream.ReadAsync(buffer);  

Read More
Asp.Net Core

ASP.NET Core Memory Grows Slowly

- 18.01.26 - ErcanOPAK comment on ASP.NET Core Memory Grows Slowly

No crash, but RAM increases. WhyScoped services hold references. TipReview service lifetimes.

Read More
Asp.Net Core

.NET Core Logs Impact Performance

- 16.01.26 - ErcanOPAK comment on .NET Core Logs Impact Performance

Logging enabled, speed drops. WhySynchronous log providers. TipUse async logging.

Read More
Asp.Net Core

ASP.NET Core Startup Becomes Slower

- 16.01.26 - ErcanOPAK comment on ASP.NET Core Startup Becomes Slower

App works, boot time grows. WhyHeavy work in ConfigureServices. TipDefer non-critical initialization.

Read More
Asp.Net Core

.NET Core Memory Grows Without Leaks

- 15.01.26 - ErcanOPAK comment on .NET Core Memory Grows Without Leaks

GC runs, memory stays high. WhyPinned objects block compaction. TipAvoid pinning unless absolutely required.

Read More
Asp.Net Core

ASP.NET Core APIs Return Inconsistent Results

- 15.01.26 - ErcanOPAK comment on ASP.NET Core APIs Return Inconsistent Results

Same request, different responses. WhyMutable singleton services. TipKeep singletons stateless.

Read More
Asp.Net Core

.NET Core Apps Restart Too Often in Production

- 14.01.26 - ErcanOPAK comment on .NET Core Apps Restart Too Often in Production

No crashes logged. WhyHealth checks too aggressive. TipAlign health checks with real readiness.

Read More
Asp.Net Core

ASP.NET Core Apps Age Poorly Without Errors

- 14.01.26 - ErcanOPAK comment on ASP.NET Core Apps Age Poorly Without Errors

Performance drops silently. WhyBackground services accumulate work. TipDesign background tasks with back-pressure.

Read More
Page 3 of 7
« Previous 1 2 3 4 5 6 7 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 (754)
  • 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 (754)

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