Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

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

Tag: Async/Await

C#

C#: Fix a Thread-Static Field Resetting on an async Continuation

- 16.11.26 - ErcanOPAK comment on C#: Fix a Thread-Static Field Resetting on an async Continuation

๐Ÿ”ง C#: Fix a Thread-Static Field Resetting on an async Continuation A [ThreadStatic] field’s value is tied to the physical OS thread that set it, not to any logical notion of “the current request.” When an await inside an async method yields and later resumes, the thread pool is free to resume that continuation on […]

Read More
C#

C#: Fix a Monitor Lock Held Across an await by the Wrong Thread

- 15.11.26 - ErcanOPAK comment on C#: Fix a Monitor Lock Held Across an await by the Wrong Thread

๐Ÿ”ง C#: Fix a Monitor Lock Held Across an await by the Wrong Thread The compiler flatly refuses to let you write await directly inside a lock statement — a compile error that exists specifically to prevent a real deadlock risk. Working around it by manually calling Monitor.Enter/Monitor.Exit instead compiles fine, because Monitor has no […]

Read More
JavaScript

JavaScript: Fix a Promise.allSettled Call Reporting Every Promise as Fulfilled Even Though One of the Underlying Fetches Actually Failed Because a catch Block Inside It Swallowed the Rejection and Returned an Ordinary Value

- 11.11.26 - ErcanOPAK comment on JavaScript: Fix a Promise.allSettled Call Reporting Every Promise as Fulfilled Even Though One of the Underlying Fetches Actually Failed Because a catch Block Inside It Swallowed the Rejection and Returned an Ordinary Value

โšก JavaScript: Fix a Promise.allSettled Call Reporting Every Promise as Fulfilled Even Though One of the Underlying Fetches Actually Failed Because a catch Block Inside It Swallowed the Rejection and Returned an Ordinary Value Promise.allSettled resolves every entry strictly based on whether that specific promise settled by resolving or rejecting — it has no way […]

Read More
C#

C#: Fix an IAsyncEnumerable Enumerating Entirely Synchronously Because the Iterator Method Never Awaits Before Its First yield return

- 09.11.26 - ErcanOPAK comment on C#: Fix an IAsyncEnumerable Enumerating Entirely Synchronously Because the Iterator Method Never Awaits Before Its First yield return

๐Ÿ”ง Fix an IAsyncEnumerable Enumerating Entirely Synchronously Because the Iterator Method Never Awaits Before Its First yield return An async iterator method returning IAsyncEnumerable<T> with yield return only actually becomes asynchronous at the points where it awaits something โ€” the compiler-generated state machine behaves exactly like a synchronous iterator up until its first genuine await. […]

Read More
C#

C#: Fix a foreach Loop Over a List Throwing InvalidOperationException Because an Awaited Continuation Still Running After the Loop Started Modified the Same List

- 08.11.26 - ErcanOPAK comment on C#: Fix a foreach Loop Over a List Throwing InvalidOperationException Because an Awaited Continuation Still Running After the Loop Started Modified the Same List

๐Ÿ”ง C#: Fix a foreach Loop Over a List Throwing InvalidOperationException Because an Awaited Continuation Still Running After the Loop Started Modified the Same List A foreach loop over a List<T> takes out an enumerator that detects structural modification to the underlying list during enumeration, throwing InvalidOperationException the moment it notices one. That’s usually understood […]

Read More
JavaScript

JavaScript: Fix Array.prototype.flat Not Flattening a Nested Array Returned From an Async Map Because the Outer Array Still Holds Unresolved Promises Instead of Arrays

- 06.11.26 - ErcanOPAK comment on JavaScript: Fix Array.prototype.flat Not Flattening a Nested Array Returned From an Async Map Because the Outer Array Still Holds Unresolved Promises Instead of Arrays

โšก JavaScript: Fix Array.prototype.flat Not Flattening a Nested Array Returned From an Async Map Because the Outer Array Still Holds Unresolved Promises Instead of Arrays Array.prototype.map with an async callback doesn’t wait for each callback to resolve before moving to the next element โ€” it immediately returns a Promise from every call, so the array […]

Read More
C#

C#: Fix ConfigureAwait(false) Not Preventing a Deadlock Because the Blocking Result Call Happens Several Awaits Downstream in a Different Method

- 05.11.26 - ErcanOPAK comment on C#: Fix ConfigureAwait(false) Not Preventing a Deadlock Because the Blocking Result Call Happens Several Awaits Downstream in a Different Method

๐Ÿ”ง C#: Fix ConfigureAwait(false) Not Preventing a Deadlock Because the Blocking Result Call Happens Several Awaits Downstream in a Different Method ConfigureAwait(false) only prevents the deadlock-causing SynchronizationContext capture for the specific await it’s attached to. A classic UI-thread or ASP.NET-classic deadlock from blocking on .Result/.Wait() over an async call chain isn’t actually fixed by adding […]

Read More
AI

The AI Prompt That Finds Every Discarded Task in Your Codebase Whose Exception Would Otherwise Vanish Into the Void

- 04.11.26 - ErcanOPAK comment on The AI Prompt That Finds Every Discarded Task in Your Codebase Whose Exception Would Otherwise Vanish Into the Void

๐Ÿค– The AI Prompt That Finds Every Discarded Task in Your Codebase Whose Exception Would Otherwise Vanish Into the Void Calling an async method and never awaiting, storing, or otherwise observing the Task it returns โ€” a bare Task.Run(…) with no assignment, a fire-and-forget call at the end of a method, a _ = SomeAsync() […]

Read More
C#

C#: Fix a TaskCompletionSource That Never Completes Because RunContinuationsAsynchronously Wasn’t Set and a Continuation Deadlocked on the Same Thread

- 01.11.26 - ErcanOPAK comment on C#: Fix a TaskCompletionSource That Never Completes Because RunContinuationsAsynchronously Wasn’t Set and a Continuation Deadlocked on the Same Thread

๐Ÿ”ง Fix a TaskCompletionSource That Never Completes Because RunContinuationsAsynchronously Wasn’t Set and a Continuation Deadlocked on the Same Thread Calling SetResult (or TrySetResult) on a TaskCompletionSource doesn’t just flip the underlying task to a completed state and move on โ€” by default, it runs every continuation waiting on that task’s completion synchronously, on the very […]

Read More
C#

C#: Fix an Async Local Function Still Capturing a Loop Variable by Reference Even Though the Outer Loop Already Uses Per-Iteration Scoping

- 31.10.26 - ErcanOPAK comment on C#: Fix an Async Local Function Still Capturing a Loop Variable by Reference Even Though the Outer Loop Already Uses Per-Iteration Scoping

๐Ÿ”ง Fix an Async Local Function Still Capturing a Loop Variable by Reference Even Though the Outer Loop Already Uses Per-Iteration Scoping Modern C# gives a foreach loop’s iteration variable a fresh scope on every single iteration, which is exactly the fix that made the old closure-captures-the-wrong-loop-value bug mostly disappear for straightforward cases, a lambda […]

Read More
JavaScript

JavaScript: Fix a Promise.allSettled Call Hiding a Rejected Promise’s Error Because Nothing Ever Inspects the Rejected Status Branch

- 30.10.26 - ErcanOPAK comment on JavaScript: Fix a Promise.allSettled Call Hiding a Rejected Promise’s Error Because Nothing Ever Inspects the Rejected Status Branch

โšก Fix a Promise.allSettled Call Hiding a Rejected Promise’s Error Because Nothing Ever Inspects the Rejected Status Branch Promise.allSettled exists specifically so one rejected promise doesn’t short-circuit the whole batch the way Promise.all would โ€” every result resolves with a `{status, value}` or `{status, reason}` object, and the call itself never rejects. That’s exactly what […]

Read More
C#

C#: Fix a ConfigureAwait(false) Call That Still Deadlocks Because a Caller Further Up the Stack Blocks on .Result

- 30.10.26 - ErcanOPAK comment on C#: Fix a ConfigureAwait(false) Call That Still Deadlocks Because a Caller Further Up the Stack Blocks on .Result

๐Ÿ”ง Fix a ConfigureAwait(false) Call That Still Deadlocks Because a Caller Further Up the Stack Blocks on .Result `ConfigureAwait(false)` only changes whether that one specific await’s continuation needs to resume on the originally captured synchronization context โ€” it protects exactly the await it’s applied to, nothing further down a call chain that it doesn’t touch. […]

Read More
C#

C#: Fix a Custom Awaiter’s Continuation Running on the Wrong Thread Because IsCompleted Returned True Before the Underlying Operation Actually Finished

- 29.10.26 - ErcanOPAK comment on C#: Fix a Custom Awaiter’s Continuation Running on the Wrong Thread Because IsCompleted Returned True Before the Underlying Operation Actually Finished

๐Ÿ”ง Fix a Custom Awaiter’s Continuation Running on the Wrong Thread Because IsCompleted Returned True Before the Underlying Operation Actually Finished Implementing a custom awaitable type – an INotifyCompletion-based awaiter with GetAwaiter, IsCompleted, and GetResult – means you’re personally responsible for the contract that IsCompleted only returns true once the operation genuinely has a result […]

Read More
Asp.Net Core

ASP.NET Core: Fix a Minimal API Endpoint Returning an Empty JSON Body Because an Async Lambda Returns an Unawaited Task Instead of the Result

- 29.10.26 - ErcanOPAK comment on ASP.NET Core: Fix a Minimal API Endpoint Returning an Empty JSON Body Because an Async Lambda Returns an Unawaited Task Instead of the Result

โš™๏ธ Fix a Minimal API Endpoint Returning an Empty JSON Body Because an Async Lambda Returns an Unawaited Task Instead of the Result A minimal API route handler’s return type decides exactly how the response gets serialized, and an async lambda that returns a Task of T without an await in its body – because […]

Read More
JavaScript

JavaScript: Fix an async Function Inside Array.prototype.map() Silently Returning an Array of Pending Promises Instead of Resolved Values

- 23.10.26 - ErcanOPAK comment on JavaScript: Fix an async Function Inside Array.prototype.map() Silently Returning an Array of Pending Promises Instead of Resolved Values

โšก Fix an async Function Inside Array.prototype.map() Silently Returning an Array of Pending Promises Instead of Resolved Values Passing an async function directly into .map() compiles and runs without any error, which is exactly what makes this bug so easy to ship: every async function implicitly returns a Promise, so .map()’s callback dutifully returns one […]

Read More
Asp.Net Core

ASP.NET Core: Fix a Controller Action That Blocks on .Result Instead of Awaiting, Quietly Exhausting Available Request Capacity Under Load

- 23.10.26 - ErcanOPAK comment on ASP.NET Core: Fix a Controller Action That Blocks on .Result Instead of Awaiting, Quietly Exhausting Available Request Capacity Under Load

โš™๏ธ Fix a Controller Action That Blocks on .Result Instead of Awaiting, Quietly Exhausting Available Request Capacity Under Load A controller action that calls an async method and reads its .Result property instead of awaiting it compiles cleanly, usually even runs correctly in local testing, and quietly ties up a thread pool worker thread for […]

Read More
C#

C#: Fix a Fire-and-Forget async Local Function’s Exception Never Reaching the Try/Catch That Calls It

- 23.10.26 - ErcanOPAK comment on C#: Fix a Fire-and-Forget async Local Function’s Exception Never Reaching the Try/Catch That Calls It

๐Ÿ”ง Calling an async Local Function Without await Detaches It From Your Try/Catch Declaring a local `async` function inside a method and calling it without `await` – often by mistake, or to intentionally kick off a background operation – produces a `Task` that’s simply discarded at the call site, and any exception that local function […]

Read More
Visual Studio

Visual Studio: Fix the Immediate Window Reporting an Async Call as Hung When the Debugger Is Simply Paused on a Different Thread

- 22.10.26 - ErcanOPAK comment on Visual Studio: Fix the Immediate Window Reporting an Async Call as Hung When the Debugger Is Simply Paused on a Different Thread

๐Ÿ› ๏ธ Why Your Await Never Comes Back in the Immediate Window Typing an async method call into the Immediate Window while stopped at a breakpoint feels like a normal function call, but it isn’t one – the debugger has to actually resume execution, let the awaited continuation run, and report the result back to you, […]

Read More
C#

C#: Fix ConfigureAwait(false) Silently Breaking a Method That Needed the Original SynchronizationContext

- 22.10.26 - ErcanOPAK comment on C#: Fix ConfigureAwait(false) Silently Breaking a Method That Needed the Original SynchronizationContext

๐Ÿ”ง ConfigureAwait(false) Is a Promise You Don’t Need to Come Back – Make Sure That’s True Adding ConfigureAwait(false) after every await is widely repeated as a blanket best practice for library code, because it avoids forcing a continuation back onto a captured context it doesn’t actually need – and that’s genuinely correct advice right up […]

Read More
Ajax

Ajax: Fix Sequential fetch() Calls That Silently Run Out of Order Because Promises Were Never Awaited Inside a forEach

- 22.10.26 - ErcanOPAK comment on Ajax: Fix Sequential fetch() Calls That Silently Run Out of Order Because Promises Were Never Awaited Inside a forEach

๐Ÿ”„ The Loop That Looks Sequential but Isn’t An async arrow function passed to Array.prototype.forEach() runs its own independent promise chain for every iteration, but forEach() itself has no idea those callbacks return promises and never waits for any of them before moving to the next item – so code that looks like it’s firing […]

Read More
C#

C#: Fix a CancellationTokenSource.CancelAfter Timer That Never Fires Because the Source Was Disposed Too Early

- 11.10.26 - ErcanOPAK comment on C#: Fix a CancellationTokenSource.CancelAfter Timer That Never Fires Because the Source Was Disposed Too Early

๐Ÿ”ง The CancelAfter Timer That Never Gets a Chance to Fire CancellationTokenSource.CancelAfter schedules an internal timer that calls Cancel once its delay elapses, but that timer belongs entirely to the CancellationTokenSource instance that scheduled it. Disposing the source before the delay elapses tears the timer down along with everything else the source owns, so the […]

Read More
C#

C#: Fix a ValueTask That Throws or Returns Garbage Because It Was Awaited Twice Instead of Once

- 11.10.26 - ErcanOPAK comment on C#: Fix a ValueTask That Throws or Returns Garbage Because It Was Awaited Twice Instead of Once

๐Ÿ”ง The ValueTask You’re Only Supposed to Await Once A ValueTask is built around a single-consumption contract that Task was never bound by: a Task can be awaited, cached in a field, and awaited again from a completely different place any number of times, but a ValueTask backed by a pooled source behind the scenes […]

Read More
C#

C#: Fix an IAsyncDisposable Object Whose DisposeAsync Never Runs Because It Was Disposed Synchronously by Mistake

- 11.10.26 - ErcanOPAK comment on C#: Fix an IAsyncDisposable Object Whose DisposeAsync Never Runs Because It Was Disposed Synchronously by Mistake

๐Ÿ”ง The DisposeAsync That Was Called the Synchronous Way A type can implement both IDisposable and IAsyncDisposable at once, which is common for anything that wraps a resource with async-friendly cleanup, like flushing a buffered stream over the network. The two interfaces look interchangeable from the call site because a using statement compiles against either […]

Read More
C#

C#: Fix a ThreadStatic Field That Silently Resets to Default Mid-Request Because an async/await Continuation Resumed on a Different Thread

- 11.10.26 - ErcanOPAK comment on C#: Fix a ThreadStatic Field That Silently Resets to Default Mid-Request Because an async/await Continuation Resumed on a Different Thread

๐Ÿ”ง The ThreadStatic Field That Forgot What Thread It’s On The ThreadStatic attribute gives a static field its own separate value per thread, which works perfectly as long as the code that sets it and the code that reads it both run on the same thread. An await point breaks that assumption without raising any […]

Read More
C#

C#: Fix a using Declaration That Silently Calls the Wrong Dispose Method on a Type That Implements Both IDisposable and IAsyncDisposable

- 10.10.26 - ErcanOPAK comment on C#: Fix a using Declaration That Silently Calls the Wrong Dispose Method on a Type That Implements Both IDisposable and IAsyncDisposable

๐Ÿ”ง The Cleanup That Ran, Just Not the One You Needed A type that implements both IDisposable and IAsyncDisposable is meant to offer two valid ways to release its resources, with the async path typically reserved for cleanup work that itself needs to be asynchronous – flushing a buffer over the network, or releasing a […]

Read More
C#

C#: Fix a Deadlock Caused by Mixing lock and await in the Same Method

- 27.09.26 - ErcanOPAK comment on C#: Fix a Deadlock Caused by Mixing lock and await in the Same Method

๐Ÿ”ง The Fix for a Compiler Error That Turned Into a Deadlock The compiler flatly refuses to let you await inside a lock block (that’s error CS1996, not a warning), which pushes developers toward the obvious substitute: SemaphoreSlim, since it has an async WaitAsync method. The substitution looks equivalent, but a plain lock is reentrant […]

Read More
C#

C#: Fix a CancellationToken That’s Passed Everywhere but Never Actually Checked

- 27.09.26 - ErcanOPAK comment on C#: Fix a CancellationToken That’s Passed Everywhere but Never Actually Checked

๐Ÿ”ง The Cancellation Token That Every Method Accepts and No Method Honors Threading a `CancellationToken` through every async method signature in a call chain looks like proper cancellation support – but simply accepting the parameter does nothing on its own; a method has to actually call `token.ThrowIfCancellationRequested()` (or pass the token into an awaited operation […]

Read More
C#

C#: Fix a Span That Throws the Moment It Crosses an Await

- 26.09.26 - ErcanOPAK comment on C#: Fix a Span That Throws the Moment It Crosses an Await

๐Ÿ”ง The Compiler Error That Shows Up Only When You Add One await `Span<T>` is a stack-only type built for high-performance, allocation-free code – and that exact property is what makes it incompatible with `async` methods, because an `async` method can be suspended and its local state moved onto the heap as part of a […]

Read More
C#

C#: Fix a Recursive Async Method That Grows the Call Stack Until It Crashes

- 06.09.26 - ErcanOPAK comment on C#: Fix a Recursive Async Method That Grows the Call Stack Until It Crashes

๐Ÿ”ง The Recursive Async Method That Grows the Call Stack Until It Just Crashes A recursive method converted to `async` still looks like it should behave like any other recursion – and for a while it does, until processing a large enough input throws a `StackOverflowException` that a non-recursive version of the same logic never […]

Read More
JavaScript

JavaScript Async/Await: Complete Guide to Clean Promise Chains

- 19.08.26 - ErcanOPAK comment on JavaScript Async/Await: Complete Guide to Clean Promise Chains

Stop the callback hell and promise pyramid! Async/await makes asynchronous JavaScript code look synchronous and maintainable. Step 1: The Problem – Promise Chains // โŒ Callback Hell getUser(1, (user) => { getOrders(user.id, (orders) => { getOrderDetails(orders[0].id, (details) => { processOrder(details, (result) => { console.log(‘Done!’, result); }); }); }); }); // โŒ Promise Pyramid getUser(1) .then(user […]

Read More
Page 1 of 2
1 2 Next ยป

Posts pagination

1 2 Next »
November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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