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 Streams

C#

C#: Fix an IAsyncEnumerable foreach Loop Hanging Forever Because the Underlying Channel Reader Was Never Completed on the Producer Side

- 12.11.26 - ErcanOPAK comment on C#: Fix an IAsyncEnumerable foreach Loop Hanging Forever Because the Underlying Channel Reader Was Never Completed on the Producer Side

🔧 C#: Fix an IAsyncEnumerable foreach Loop Hanging Forever Because the Underlying Channel Reader Was Never Completed on the Producer Side An `IAsyncEnumerable<T>` built on top of a `System.Threading.Channels.Channel<T>` — a common pattern for turning a producer/consumer queue into an async stream — relies entirely on the producer calling `channel.Writer.Complete()` once it’s genuinely done writing. […]

Read More
C#

C#: Fix an IAsyncEnumerable foreach Loop Silently Ignoring a CancellationToken Because WithCancellation Was Never Called

- 07.11.26 - ErcanOPAK comment on C#: Fix an IAsyncEnumerable foreach Loop Silently Ignoring a CancellationToken Because WithCancellation Was Never Called

🔧 C#: Fix an IAsyncEnumerable foreach Loop Silently Ignoring a CancellationToken Because WithCancellation Was Never Called An async iterator method that accepts a CancellationToken parameter and checks it internally with ThrowIfCancellationRequested will only actually see cancellation requests that are routed to it, and a plain await foreach loop over an IAsyncEnumerable<T> doesn’t pass any token […]

Read More
C#

C#: Fix WithCancellation on an IAsyncEnumerable Being Silently Ignored Because the Iterator’s Token Parameter Is Missing [EnumeratorCancellation]

- 31.10.26 - ErcanOPAK comment on C#: Fix WithCancellation on an IAsyncEnumerable Being Silently Ignored Because the Iterator’s Token Parameter Is Missing [EnumeratorCancellation]

🔧 Fix WithCancellation on an IAsyncEnumerable Being Silently Ignored Because the Iterator’s Token Parameter Is Missing [EnumeratorCancellation] Calling WithCancellation on an async enumerable at the consuming end is supposed to let the compiler-generated iterator state machine observe that token internally, but that wiring only actually happens for a cancellation token parameter on the iterator method […]

Read More
C#

C#: Fix an IAsyncEnumerable Stream Buffering Every Item Before Your foreach Loop Ever Runs Because of an Accidental ToListAsync() Upstream

- 29.10.26 - ErcanOPAK comment on C#: Fix an IAsyncEnumerable Stream Buffering Every Item Before Your foreach Loop Ever Runs Because of an Accidental ToListAsync() Upstream

🔧 Fix an IAsyncEnumerable Stream Buffering Every Item Before Your foreach Loop Ever Runs Because of an Accidental ToListAsync() Upstream The entire point of returning IAsyncEnumerable<T> from a method is that the caller’s await foreach can start processing the first item as soon as it’s available, without the whole sequence ever needing to exist in […]

Read More
C#

C#: Fix an IAsyncEnumerable Loop Silently Running One Item at a Time Even Though You Wrapped It in Task.WhenAll

- 21.10.26 - ErcanOPAK comment on C#: Fix an IAsyncEnumerable Loop Silently Running One Item at a Time Even Though You Wrapped It in Task.WhenAll

🔧 The Parallel Loop That Was Never Actually Parallel An await foreach loop over an IAsyncEnumerable<T> pulls items one at a time by design – each MoveNextAsync call on the underlying async iterator has to complete before the next one starts, since that’s fundamentally how pull-based async streaming works. Wrapping the per-item work inside that […]

Read More
C#

C#: Async Streams for Real-time Data Processing

- 17.08.26 - ErcanOPAK comment on C#: Async Streams for Real-time Data Processing

🌊 Async Streams = Real-time Data Real-time data needs streaming. Async streams enable efficient, asynchronous processing of real-time data. 📝 Async Stream Basics // Async Stream Method public async IAsyncEnumerable GenerateNumbersAsync() { for (int i = 0; i < 10; i++) { await Task.Delay(1000); yield return i; } } // Consuming Async Stream await foreach […]

Read More
C#

C#: Use Async Streams for Asynchronous Data Sequences

- 09.07.26 - ErcanOPAK comment on C#: Use Async Streams for Asynchronous Data Sequences

🌊 Async Streams = Asynchronous Data Sync streams block. IAsyncEnumerable is async. Process data as it arrives, non-blocking, efficient. 📝 Async Streams Basics // Async stream method async IAsyncEnumerable GenerateNumbersAsync() { for (int i = 0; i < 10; i++) { await Task.Delay(100); // Simulate async work yield return i; } } // Consume async […]

Read More
C#

C#: Use IAsyncEnumerable for Streaming Large Data Sets

- 15.02.26 - ErcanOPAK comment on C#: Use IAsyncEnumerable for Streaming Large Data Sets

Loading all results into memory first is wasteful. IAsyncEnumerable streams results as they’re retrieved. Old Way – Load Everything: public async Task GetOrdersAsync() { return await _db.Orders.ToListAsync(); // Loads all 1 million orders into memory! } // Caller: var orders = await GetOrdersAsync(); // 5GB in memory foreach (var order in orders) ProcessOrder(order); Stream with […]

Read More
C#

C#: Use Channels for Producer-Consumer Patterns (Better Than BlockingCollection)

- 03.02.26 - ErcanOPAK comment on C#: Use Channels for Producer-Consumer Patterns (Better Than BlockingCollection)

Processing queue of tasks between threads? System.Threading.Channels provides async-first, high-performance producer-consumer patterns. Install Package: dotnet add package System.Threading.Channels Basic Producer-Consumer: using System.Threading.Channels; // Create unbounded channel var channel = Channel.CreateUnbounded(); // Producer task var producer = Task.Run(async () => { for (int i = 0; i < 100; i++) { await channel.Writer.WriteAsync($"Message {i}"); await Task.Delay(10); […]

Read More
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