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

Author: ErcanOPAK

Asp.Net Core

IHostedService vs BackgroundService

- 17.12.25 - ErcanOPAK comment on IHostedService vs BackgroundService

Many misuse them. đź§  Difference IHostedService = lifecycle hooks BackgroundService = long-running loops âś… Rule Use BackgroundService for workers.

Read More
Asp.Net Core / C#

Middleware Order Can Break Security

- 17.12.25 - ErcanOPAK comment on Middleware Order Can Break Security

Order matters a lot. ❌ Wrong UseEndpoints(); UseAuthentication(); âś… Correct UseAuthentication(); UseAuthorization(); UseEndpoints();  

Read More
SQL

NOT IN vs NOT EXISTS — One Can Return Wrong Results

- 17.12.25 - ErcanOPAK comment on NOT IN vs NOT EXISTS — One Can Return Wrong Results

WHERE Id NOT IN (SELECT UserId FROM BannedUsers) ❌ Problem If subquery returns NULL, results are wrong. âś… Always Safer WHERE NOT EXISTS ( SELECT 1 FROM BannedUsers b WHERE b.UserId = u.Id )  

Read More
SQL

SELECT * Breaks Index Usage

- 17.12.25 - ErcanOPAK comment on SELECT * Breaks Index Usage

This kills performance: SELECT * FROM Orders đź§  Why Forces key lookups Breaks covering indexes âś… Fix Select only what you need: SELECT Id, Total FROM Orders  

Read More
C#

Structs Aren’t Always Faster Than Classes

- 17.12.25 - ErcanOPAK comment on Structs Aren’t Always Faster Than Classes

Many devs assume structs = faster. ❌ Reality Large structs copy memory Passed by value by default ✅ Rule of Thumb Small, immutable → struct Complex objects → class

Read More
C# / LINQ

LINQ ToList() — The Performance Trap

- 17.12.25 - ErcanOPAK comment on LINQ ToList() — The Performance Trap

This line is expensive: var users = query.ToList(); đź§  Why Executes immediately Loads everything into memory âś… Better Stream or filter first: var users = query.Where(x => x.IsActive);  

Read More
C#

async void — The Exception Black Hole

- 17.12.25 - ErcanOPAK comment on async void — The Exception Black Hole

This should almost never exist: async void DoWork() ❌ Why it’s dangerous Exceptions crash the process Cannot be awaited Impossible to test ✅ Correct async Task DoWorkAsync() Only valid use: event handlers.

Read More
Visual Studio

Visual Studio Debugger Skips Lines — Optimized Build Trap

- 16.12.25 - ErcanOPAK comment on Visual Studio Debugger Skips Lines — Optimized Build Trap

Debugger lies when optimization is on. ✅ Fix Build Configuration → DebugDisable Optimize Code

Read More
Wordpress

WordPress Admin Slow — Heartbeat API Overload

- 16.12.25 - ErcanOPAK comment on WordPress Admin Slow — Heartbeat API Overload

Heartbeat runs every 15s. âś… Fix Reduce frequency or disable on non-edit pages. Result Lower CPU Faster admin

Read More
Windows

SSD Slow on Windows 11 — TRIM Disabled

- 16.12.25 - ErcanOPAK comment on SSD Slow on Windows 11 — TRIM Disabled

Check: fsutil behavior query DisableDeleteNotify 0 = enabled1 = disabled (bad)

Read More
Windows

Windows 11 Random Freezes — Power Plan Trap

- 16.12.25 - ErcanOPAK comment on Windows 11 Random Freezes — Power Plan Trap

Balanced mode throttles CPUs aggressively. ✅ Fix Power Settings → High Performance

Read More
Ajax / JavaScript

Silent AJAX Failures — Missing Content-Type

- 16.12.25 - ErcanOPAK comment on Silent AJAX Failures — Missing Content-Type

Backend never hits controller? âś… Fix headers: { “Content-Type”: “application/json” }  

Read More
JavaScript

forEach + async — A Hidden Logic Bug

- 16.12.25 - ErcanOPAK comment on forEach + async — A Hidden Logic Bug

This does not await: array.forEach(async x => await save(x)); âś… Fix for (const x of array) { await save(x); }  

Read More
HTML

loading=”lazy” — Free Performance Win

- 16.12.25 - ErcanOPAK comment on loading=”lazy” — Free Performance Win

<img src=”hero.jpg” loading=”lazy”> Why Faster initial load Lower bandwidth Better Core Web Vitals

Read More
CSS

100vh Breaks Mobile Layouts — Here’s Why

- 16.12.25 - ErcanOPAK comment on 100vh Breaks Mobile Layouts — Here’s Why

Mobile browsers resize viewport dynamically. âś… Fix height: 100svh; or JS-calculated height.

Read More
Asp.Net Core / C#

HttpClient Socket Exhaustion — Still Happening in 2025

- 16.12.25 - ErcanOPAK comment on HttpClient Socket Exhaustion — Still Happening in 2025

This is wrong: new HttpClient(); âś… Correct builder.Services.AddHttpClient(); Why Reuses sockets Prevents random timeouts

Read More
Asp.Net Core / C#

Minimal APIs — Why Filters Replace Middleware

- 16.12.25 - ErcanOPAK comment on Minimal APIs — Why Filters Replace Middleware

Middleware runs for every request. âś… Endpoint Filter app.MapPost(“/orders”, handler) .AddEndpointFilter<AuthFilter>(); Why Faster Scoped Cleaner

Read More
SQL

Missing WHERE on UPDATE — Disaster Prevention Trick

- 16.12.25 - ErcanOPAK comment on Missing WHERE on UPDATE — Disaster Prevention Trick

Human error happens. âś… Safety Pattern BEGIN TRAN UPDATE Users SET IsActive = 0 WHERE LastLogin < ‘2022-01-01’ — sanity check SELECT @@ROWCOUNT ROLLBACK  

Read More
SQL

Parameter Sniffing — The Query That Works… Until It Doesn’t

- 16.12.25 - ErcanOPAK comment on Parameter Sniffing — The Query That Works… Until It Doesn’t

Same query, different performance. đź§  Root cause SQL caches execution plans based on the first parameter. âś… Fix Options OPTION (RECOMPILE) or OPTIMIZE FOR UNKNOWN  

Read More
C#

ValueTask — Faster but Dangerous

- 16.12.25 - ErcanOPAK comment on ValueTask — Faster but Dangerous

ValueTask<int> GetAsync(); âš  Hidden traps Cannot await twice Harder debugging âś… Rule Use only when result is usually synchronous.

Read More
C#

ConfigureAwait(false) — When It Actually Matters

- 16.12.25 - ErcanOPAK comment on ConfigureAwait(false) — When It Actually Matters

Using it everywhere is wrong. ✅ Use it when: Library code No UI / request context needed await httpClient.GetAsync(url) .ConfigureAwait(false); ❌ Avoid in: ASP.NET Core (no sync context) UI event handlers

Read More
C#

Task.Run() in ASP.NET — The Silent Scalability Killer

- 16.12.25 - ErcanOPAK comment on Task.Run() in ASP.NET — The Silent Scalability Killer

This looks harmless: Task.Run(() => DoWork()); ❌ Why it breaks production Bypasses request lifecycle Ignores cancellation Starves thread pool under load âś… Correct Pattern Use background services: public class Worker : BackgroundService { protected override async Task ExecuteAsync(CancellationToken ct) { while (!ct.IsCancellationRequested) await DoWorkAsync(ct); } }  

Read More
Visual Studio

Visual Studio “IntelliSense Wrong Types” — Stale Solution Cache

- 15.12.25 - ErcanOPAK comment on Visual Studio “IntelliSense Wrong Types” — Stale Solution Cache

Types show incorrectly? Suggestions are wrong? ✅ Fix Close VS and delete: .vs/ bin/ obj/ Reopen solution → fixed.

Read More
Wordpress

WordPress REST API Slow — Disable Unused Endpoints

- 15.12.25 - ErcanOPAK comment on WordPress REST API Slow — Disable Unused Endpoints

Every REST route loads on init. âś… Fix Disable what you don’t use via plugin or code: remove_action(‘rest_api_init’, ‘wp_oembed_register_route’); Result Lower memory usage and faster responses.

Read More
Windows

Windows 11 Laptop Fans Always Loud — Background Indexing

- 15.12.25 - ErcanOPAK comment on Windows 11 Laptop Fans Always Loud — Background Indexing

Search indexing runs aggressively on SSDs. ✅ Fix Settings → Privacy → Searching Windows → Reduce indexing scope.

Read More
Windows

Windows 11 Slow Boot After Updates — Startup App Priority

- 15.12.25 - ErcanOPAK comment on Windows 11 Slow Boot After Updates — Startup App Priority

Windows sometimes re-enables heavy startup apps. ✅ Fix Task Manager → Startup → Disable non-essential apps. Result Faster boot and login.

Read More
Ajax / JavaScript

AJAX Requests Timeout Randomly — Browser Connection Limits

- 15.12.25 | 15.12.25 - ErcanOPAK comment on AJAX Requests Timeout Randomly — Browser Connection Limits

Browsers limit concurrent connections per domain. âś… Fix Throttle requests or queue them: await Promise.allSettled(queue.map(run)); Especially important for dashboards batch uploads

Read More
JavaScript

JS “Undefined Is Not Null” — The Bug That Breaks APIs

- 15.12.25 - ErcanOPAK comment on JS “Undefined Is Not Null” — The Bug That Breaks APIs

undefined !== null âś… Defensive Check if (value == null) { // catches both null and undefined } Use strict checks only when you really need them.

Read More
HTML

HTML5 autocomplete — Stop Browsers From Guessing Wrong

- 15.12.25 - ErcanOPAK comment on HTML5 autocomplete — Stop Browsers From Guessing Wrong

Browsers often autofill incorrect data. âś… Control It <input name=”email” autocomplete=”email”> <input name=”one-time-code” autocomplete=”one-time-code”> Why Improves UX and security.

Read More
CSS

CSS position: sticky Not Working? Here’s Why

- 15.12.25 - ErcanOPAK comment on CSS position: sticky Not Working? Here’s Why

Sticky fails when parent has: overflow: hidden; âś… Fix Remove overflow or move sticky element higher in the DOM. Sticky only works inside scrollable ancestors.

Read More
Page 54 of 69
« Previous 1 … 49 50 51 52 53 54 55 56 57 58 59 … 69 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 (751)
  • 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 (751)

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