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

SQL

Fix Deadlocks by Understanding Lock Ordering and Using Proper Isolation Levels

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Fix Deadlocks by Understanding Lock Ordering and Using Proper Isolation Levels

Getting “Transaction was deadlocked” errors randomly? Deadlocks happen when two transactions lock resources in opposite order. Here’s how to fix them permanently. Identify Deadlocks – System Health Session: — SQL Server automatically logs deadlocks to system_health session SELECT CAST(target_data AS XML) AS deadlock_xml FROM sys.dm_xe_session_targets st JOIN sys.dm_xe_sessions s ON s.address = st.event_session_address WHERE s.name […]

Read More
SQL

SQL Server: Find Slow Queries with Query Store (No Third-Party Tools Needed)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on SQL Server: Find Slow Queries with Query Store (No Third-Party Tools Needed)

Application running slow but can’t figure out which queries are the culprits? Query Store is SQL Server’s built-in performance tracker that records everything. Enable Query Store (SQL Server 2016+): — Enable for your database ALTER DATABASE YourDatabaseName SET QUERY_STORE = ON ( OPERATION_MODE = READ_WRITE, DATA_FLUSH_INTERVAL_SECONDS = 900, INTERVAL_LENGTH_MINUTES = 60, MAX_STORAGE_SIZE_MB = 1000, QUERY_CAPTURE_MODE […]

Read More
Asp.Net Core / C#

.NET Core: Fix Memory Leaks by Understanding IDisposable and Using Patterns

- 01.02.26 | 01.02.26 - ErcanOPAK comment on .NET Core: Fix Memory Leaks by Understanding IDisposable and Using Patterns

Your .NET application’s memory usage grows infinitely? You’re probably not disposing resources properly. Here’s the complete guide. The Memory Leak – Classic Example: // WRONG: Memory leak public async Task ProcessOrdersAsync() { var dbContext = new ApplicationDbContext(); var orders = await dbContext.Orders.ToListAsync(); // Process orders… // dbContext never disposed = connection stays open = memory […]

Read More
Asp.Net Core

.NET Core: Reduce Docker Image Build Time with Layer Caching Optimization

- 01.02.26 | 01.02.26 - ErcanOPAK comment on .NET Core: Reduce Docker Image Build Time with Layer Caching Optimization

Your .NET Docker builds take 5-10 minutes every time? Improper Dockerfile layer ordering is killing your cache efficiency. Bad Dockerfile (No Cache Optimization): FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src # This invalidates cache on EVERY code change COPY . . RUN dotnet restore RUN dotnet build -c Release RUN dotnet publish -c Release -o /app/publish […]

Read More
Git

Speed Up Git Operations 10x by Cleaning Up Bloated Repository History

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Speed Up Git Operations 10x by Cleaning Up Bloated Repository History

Is ‘git clone’ taking 10 minutes? Your repository probably has bloated history from large files that were deleted years ago but still exist in Git’s object database. Diagnose the Problem: # Check repository size du -sh .git # If this is >500MB for a code project, you have bloat # Find largest objects in Git […]

Read More
Git

Recover Deleted Git Commits Even After Hard Reset (It’s Not Gone)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Recover Deleted Git Commits Even After Hard Reset (It’s Not Gone)

Accidentally did ‘git reset –hard’ and lost hours of work? Your commits aren’t deleted – they’re just orphaned. Here’s how to find them. The Magic Command – Reflog: git reflog This shows every HEAD movement in your repository, even deleted commits. Output looks like: a1b2c3d HEAD@{0}: reset: moving to HEAD~3 e4f5g6h HEAD@{1}: commit: Added user […]

Read More
Ajax / JavaScript

Handle AJAX Errors Properly: Retry Logic with Exponential Backoff

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Handle AJAX Errors Properly: Retry Logic with Exponential Backoff

Your AJAX calls fail randomly due to network hiccups or server load? Implement smart retry logic that actually works. The Problem with Basic Retry: // Bad: Immediate retry can make things worse function badRetry(url, maxAttempts) { for (let i = 0; i < maxAttempts; i++) { try { return await fetch(url); } catch (error) { […]

Read More
JavaScript

Debounce vs Throttle in JavaScript: When to Use Which (With Real Examples)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Debounce vs Throttle in JavaScript: When to Use Which (With Real Examples)

Search inputs lagging? Scroll events killing performance? Understanding debounce vs throttle is critical for responsive UIs. Debounce – Wait Until User Stops: function debounce(func, delay) { let timeoutId; return function(…args) { clearTimeout(timeoutId); timeoutId = setTimeout(() => { func.apply(this, args); }, delay); }; } // Usage: Search input const searchInput = document.getElementById(‘search’); const performSearch = debounce((query) […]

Read More
HTML

Use HTML Dialog Element for Accessible Modals (Forget JavaScript Libraries)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Use HTML Dialog Element for Accessible Modals (Forget JavaScript Libraries)

Still using Bootstrap modals or custom JavaScript? The native <dialog> element handles accessibility, focus trapping, and backdrop clicks automatically. The Complete HTML: <!– The dialog element –> <dialog id=”myModal”> <form method=”dialog”> <h2>Confirm Action</h2> <p>Are you sure you want to delete this item?</p> <div class=”actions”> <button value=”cancel”>Cancel</button> <button value=”confirm” autofocus>Delete</button> </div> </form> </dialog> <!– Trigger button […]

Read More
CSS

Create Smooth Page Transitions with CSS View Transitions API (No JavaScript)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Create Smooth Page Transitions with CSS View Transitions API (No JavaScript)

Page navigation feels jarring? The new CSS View Transitions API creates native app-like transitions without a single line of JavaScript. The Basic Setup: /* Enable view transitions for all navigations */ @view-transition { navigation: auto; } /* Customize the transition */ ::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.3s; animation-timing-function: ease-in-out; } /* Fade effect */ ::view-transition-old(root) { […]

Read More
Windows

Fix Windows 11 Slow Boot by Cleaning Up Startup Items (PowerShell Method)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Fix Windows 11 Slow Boot by Cleaning Up Startup Items (PowerShell Method)

Windows taking 2-3 minutes to reach the desktop? Your startup folder is probably cluttered with apps you don’t need launching immediately. See What’s Slowing Your Boot: # PowerShell command to list all startup programs with delay impact Get-CimInstance -ClassName Win32_StartupCommand | Select-Object Name, Command, Location, User | Format-Table -AutoSize This shows every program that auto-starts, […]

Read More
Windows

Disable Windows 11 Bloatware and Telemetry with PowerShell (Takes 2 Minutes)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Disable Windows 11 Bloatware and Telemetry with PowerShell (Takes 2 Minutes)

Fresh Windows 11 install comes with 30+ unnecessary apps and aggressive telemetry. Here’s the nuclear option to clean it all at once. The One-Script Solution: Open PowerShell as Administrator and run: # Remove bloatware apps Get-AppxPackage -AllUsers | Where-Object { $_.Name -like “*Xbox*” -or $_.Name -like “*3DViewer*” -or $_.Name -like “*Solitaire*” -or $_.Name -like “*Spotify*” […]

Read More
AI

AI Prompt: Plan the Perfect Road Trip with Hidden Gems and Time Optimization

- 01.02.26 | 01.02.26 - ErcanOPAK comment on AI Prompt: Plan the Perfect Road Trip with Hidden Gems and Time Optimization

Skip generic tourist traps and discover authentic local experiences with this comprehensive road trip planning prompt. The Ultimate Road Trip Planner Prompt: You are a travel planning expert with deep knowledge of hidden gems and local culture. Create a detailed road trip itinerary. **Trip Details:** – Start: [City/Location] – End: [City/Location] – Duration: [Number of […]

Read More
AI

AI Prompt: Debug Production Errors by Analyzing Stack Traces and Logs

- 01.02.26 | 01.02.26 - ErcanOPAK comment on AI Prompt: Debug Production Errors by Analyzing Stack Traces and Logs

Stop spending hours deciphering cryptic error messages. This prompt turns stack traces into actionable debugging steps. The Master Debugging Prompt: You are a senior software engineer debugging a production issue. Analyze the following error and provide a step-by-step debugging plan. **Error Context:** Application: [e.g., ASP.NET Core Web API] Environment: [Production/Staging] Frequency: [How often does this […]

Read More
AI

AI Prompt: Generate Production-Ready API Documentation from Code Comments

- 01.02.26 | 01.02.26 - ErcanOPAK comment on AI Prompt: Generate Production-Ready API Documentation from Code Comments

Turn scattered code comments into beautiful, structured API docs in seconds with this prompt template. The Prompt Template: You are a technical documentation expert. Analyze the following code and generate comprehensive API documentation. **Input Code:** [PASTE YOUR CODE HERE] **Output Requirements:** 1. Extract all public methods/endpoints 2. For each endpoint, document: – HTTP method and […]

Read More
Docker

Reduce Docker Image Sizes by 10x with Multi-Stage Builds

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Reduce Docker Image Sizes by 10x with Multi-Stage Builds

Your Docker image is 1.2GB when it should be 120MB? Multi-stage builds eliminate build dependencies from your final image. The Problem – Single Stage Build: FROM node:18 WORKDIR /app COPY package*.json ./ RUN npm install # Installs 300MB of dev dependencies COPY . . RUN npm run build # Creates 10MB production build CMD [“node”, […]

Read More
Kubernetes

Debug Kubernetes Pods That Keep Crashing Before Logs Disappear

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Debug Kubernetes Pods That Keep Crashing Before Logs Disappear

Your pod crashes in 2 seconds, and logs vanish before you can read them? Here’s how to catch the output before Kubernetes deletes the container. The Problem: When a pod CrashLoops, the container exits so fast that ‘kubectl logs’ shows nothing useful or “container not found” errors. By the time you run the command, Kubernetes […]

Read More
Wordpress

Recover Deleted WordPress Posts from Database (Even Without Backups)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Recover Deleted WordPress Posts from Database (Even Without Backups)

Accidentally permanently deleted a post? If you acted within 30 days and your host hasn’t optimized the database, there’s a good chance it’s still recoverable. How WordPress “Deletes” Posts: When you empty trash, WordPress doesn’t immediately erase the post row. It updates the post_status to ‘trash’ first, then later to ‘inherit’ (for revisions). The actual […]

Read More
Wordpress

Stop WordPress Comment Spam Without Plugins Using This .htaccess Rule

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Stop WordPress Comment Spam Without Plugins Using This .htaccess Rule

Getting hundreds of spam comments daily? Here’s a plugin-free solution that blocks 95% of spam bots at the server level. The Problem: Most spam bots post comments by directly hitting your wp-comments-post.php file, bypassing your website’s front-end entirely. Anti-spam plugins catch this AFTER it reaches WordPress, wasting server resources processing garbage requests. The Solution – […]

Read More
Photoshop

Fix Photoshop Lag on High-Resolution Displays with This GPU Setting

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Fix Photoshop Lag on High-Resolution Displays with This GPU Setting

Is Photoshop stuttering on your 4K monitor while other apps run smoothly? The problem isn’t your GPU – it’s how Photoshop uses it. The Issue: Modern GPUs have multiple performance modes. Photoshop often defaults to “power saving” mode on laptops or multi-monitor setups, limiting GPU acceleration even when plugged in and running intensive edits. The […]

Read More
Photoshop

Remove Photoshop’s Annoying ‘Save As’ Cloud Dialog Forever in 3 Clicks

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Remove Photoshop’s Annoying ‘Save As’ Cloud Dialog Forever in 3 Clicks

Tired of Photoshop forcing you into Creative Cloud save dialogs every single time? Here’s the permanent fix. The Frustration: Adobe changed the default ‘Save As’ behavior to push their cloud services. What used to be a simple Ctrl+Shift+S now opens a cloud upload dialog, adding 4-5 extra clicks to save files locally. The 3-Click Fix: […]

Read More
Visual Studio

Speed Up Visual Studio 2022 Build Times by 60% with This Hidden Setting

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Speed Up Visual Studio 2022 Build Times by 60% with This Hidden Setting

If your Visual Studio builds are taking forever, there’s a game-changing setting most developers miss entirely. The Problem: By default, Visual Studio uses only ONE CPU core for parallel project builds, even if you have 8, 16, or more cores available. This bottleneck can turn a 30-second build into a 2-minute nightmare. The Solution: Tools […]

Read More
C#

Why Exceptions Are Slower Than You Think

- 31.01.26 - ErcanOPAK comment on Why Exceptions Are Slower Than You Think

Exceptions are control-flow bombs. Cost Stack trace capture Heap allocations Cache pollution Rule Exceptions = exceptional cases. Alternative if (!TryParse(value, out result)) { // handle } Cause → Effect Using exceptions as logic → invisible performance debt.

Read More
C#

The Hidden Cost of record Types in Hot Paths

- 31.01.26 - ErcanOPAK comment on The Hidden Cost of record Types in Hot Paths

Records are great.Until you overuse them. Why Value-based equality Copy semantics More allocations in loops Rule Use records for: DTOs Messages Boundaries Avoid in: Hot loops Performance-critical paths

Read More
C#

Why async Code Can Still Block Threads

- 31.01.26 - ErcanOPAK comment on Why async Code Can Still Block Threads

Async ≠ non-blocking by default. The trap await Task.Run(() => LongCpuWork()); You just moved blocking to the thread pool. Rule Async is for I/O, not CPU. Correct Use async APIs for I/OUse background workers for CPU

Read More
SQL

Why COUNT(*) Gets Slow on “Big Enough” Tables

- 31.01.26 - ErcanOPAK comment on Why COUNT(*) Gets Slow on “Big Enough” Tables

It’s not the count.It’s locking + metadata access. Reality COUNT must respect: Isolation level Pending writes Allocation metadata Production alternative Use approximate counts for dashboards. Why Accuracy isn’t always worth blocking.

Read More
SQL

Why Your Index Exists But Is Never Used

- 31.01.26 - ErcanOPAK comment on Why Your Index Exists But Is Never Used

The index is fine.The predicate is not. Example WHERE YEAR(OrderDate) = 2024 Why it fails Functions on columns prevent index seeks. Rewrite WHERE OrderDate >= ‘2024-01-01’ AND OrderDate < ‘2025-01-01’ Cause → Effect Function → scan → CPU spike → slow queries.

Read More
Asp.Net Core

Why IHttpClientFactory Can Still Exhaust Sockets

- 31.01.26 - ErcanOPAK comment on Why IHttpClientFactory Can Still Exhaust Sockets

Most people think it magically fixes everything. Reality Misusing named clients causes: DNS caching issues Handler lifetime misuse Hidden fix Use typed clients for long-lived services. Why Typed clients scope handlers correctly to the service lifetime.

Read More
Asp.Net Core / C#

Why BackgroundServices Die Silently in Production

- 31.01.26 - ErcanOPAK comment on Why BackgroundServices Die Silently in Production

Looks fine locally.Stops running in prod. Root cause Unhandled exceptions inside ExecuteAsync. What actually happens The host kills the service quietly. Correct pattern protected override async Task ExecuteAsync(CancellationToken ct) { while (!ct.IsCancellationRequested) { try { await DoWork(ct); } catch (Exception ex) { logger.LogError(ex, “Background task failed”); await Task.Delay(5000, ct); } } } Cause → Effect […]

Read More
Git

The Hidden Cost of Large Commits (It’s Not Code Review)

- 31.01.26 - ErcanOPAK comment on The Hidden Cost of Large Commits (It’s Not Code Review)

Big commits don’t just slow reviews. Real damage Breaks git bisect Makes rollback risky Hides causal relationships Rule One commit = one reason. Mental model If you can’t describe the commit in one sentence, it’s too big.

Read More
Page 24 of 69
« Previous 1 … 19 20 21 22 23 24 25 26 27 28 29 … 69 Next »

Posts pagination

« Previous 1 … 22 23 24 25 26 … 69 Next »
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 (865)
  • Get the First and Last Word from a String or Sentence in SQL (837)
  • How to select distinct rows in a datatable in C# (806)
  • 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 (534)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (491)
  • Find numbers with more than two decimal places in SQL (449)

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 (865)
  • Get the First and Last Word from a String or Sentence in SQL (837)
  • How to select distinct rows in a datatable in C# (806)
  • 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