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: Background Services

Asp.Net Core

ASP.NET Core: Fix a Channel-Based Background Queue Processor Silently Stalling Forever Because an Unhandled Exception Inside the Reader Loop Ended the Task Without Restarting It

- 06.11.26 - ErcanOPAK comment on ASP.NET Core: Fix a Channel-Based Background Queue Processor Silently Stalling Forever Because an Unhandled Exception Inside the Reader Loop Ended the Task Without Restarting It

⚙️ ASP.NET Core: Fix a Channel-Based Background Queue Processor Silently Stalling Forever Because an Unhandled Exception Inside the Reader Loop Ended the Task Without Restarting It A common pattern for a background work queue is a Channel paired with a BackgroundService whose run loop reads from the channel and processes each item as it arrives […]

Read More
Asp.Net Core

ASP.NET Core: Fix a Background IHostedService Never Receiving Its Cancellation Signal Because the App Was Stopped With a Hard Kill Instead of a Graceful Shutdown

- 05.11.26 - ErcanOPAK comment on ASP.NET Core: Fix a Background IHostedService Never Receiving Its Cancellation Signal Because the App Was Stopped With a Hard Kill Instead of a Graceful Shutdown

⚙️ ASP.NET Core: Fix a Background IHostedService Never Receiving Its Cancellation Signal Because the App Was Stopped With a Hard Kill Instead of a Graceful Shutdown IHostedService.StopAsync — and the CancellationToken passed into a BackgroundService‘s ExecuteAsync — only ever get signaled as part of the generic host’s graceful shutdown sequence, triggered by SIGTERM (or its […]

Read More
Asp.Net Core

ASP.NET Core: Fix a Background IHostedService Never Stopping Gracefully Because StopAsync Ignores the CancellationToken It’s Given

- 01.11.26 - ErcanOPAK comment on ASP.NET Core: Fix a Background IHostedService Never Stopping Gracefully Because StopAsync Ignores the CancellationToken It’s Given

⚙️ Fix a Background IHostedService Never Stopping Gracefully Because StopAsync Ignores the CancellationToken It’s Given The host calls StopAsync on every registered IHostedService during shutdown and passes it a CancellationToken that gets canceled once the configured shutdown timeout elapses, which exists specifically so a service that’s taking too long to stop can be told, in […]

Read More
Asp.Net Core

ASP.NET Core: Fix a Hosted Service’s StopAsync That Gets Cut Off Before It Finishes Because the Default Shutdown Timeout Is Too Short

- 16.10.26 - ErcanOPAK comment on ASP.NET Core: Fix a Hosted Service’s StopAsync That Gets Cut Off Before It Finishes Because the Default Shutdown Timeout Is Too Short

⚙️ The Hosted Service That Never Got to Finish Saying Goodbye IHostedService.StopAsync exists so background work can wind down cleanly during shutdown – flushing a queue, closing a connection, letting an in-flight loop observe its cancellation token and exit gracefully. What’s easy to overlook is that the host only waits HostOptions.ShutdownTimeout (five seconds by default) […]

Read More
Asp.Net Core

ASP.NET Core: Fix a Hosted Service Whose StartAsync Silently Blocks the Entire App From Finishing Startup

- 10.10.26 - ErcanOPAK comment on ASP.NET Core: Fix a Hosted Service Whose StartAsync Silently Blocks the Entire App From Finishing Startup

⚙️ The Startup Task That Startup Was Waiting On The generic host awaits every registered IHostedService’s StartAsync method, one after another, before it considers the application started and begins accepting traffic – and by default there’s no timeout on how long that wait can take. A StartAsync implementation that performs real work before returning, such […]

Read More
Asp.Net Core

Background Services and IHostedService in ASP.NET Core: Complete Guide

- 23.08.26 - ErcanOPAK comment on Background Services and IHostedService in ASP.NET Core: Complete Guide

🔄 Key Takeaways: Run background tasks, scheduled jobs, and long-running operations with IHostedService and BackgroundService. Your app needs to do things in the background. Background Services are the answer. 🚀 Create Background Service // ✅ Simple background service public class SampleBackgroundService : BackgroundService { private readonly ILogger<SampleBackgroundService> _logger; public SampleBackgroundService(ILogger<SampleBackgroundService> logger) { _logger = logger; […]

Read More
Asp.Net Core

.NET Core: Background Services with IHostedService

- 15.08.26 - ErcanOPAK comment on .NET Core: Background Services with IHostedService

⏰ Background Services = Automation Background tasks are essential. IHostedService with DI enables reliable background processing. 📝 Background Service Implementation // Simple Background Service public class TimedBackgroundService : BackgroundService { private readonly ILogger _logger; private readonly IServiceProvider _serviceProvider; public TimedBackgroundService(ILogger logger, IServiceProvider serviceProvider) { _logger = logger; _serviceProvider = serviceProvider; } protected override async Task […]

Read More
Asp.Net Core

.NET Core: Use Background Services for Long-Running Tasks

- 30.03.26 - ErcanOPAK comment on .NET Core: Use Background Services for Long-Running Tasks

⏰ Tasks That Run Forever Need to process queue every minute? Send emails in background? Background Services run continuously alongside your ASP.NET app. Perfect for scheduled tasks, workers. Create Background Service public class EmailProcessorService : BackgroundService { private readonly ILogger _logger; private readonly IServiceProvider _serviceProvider; public EmailProcessorService( ILogger logger, IServiceProvider serviceProvider) { _logger = logger; […]

Read More
Asp.Net Core

.NET Core: Use IHostedService for Background Tasks

- 22.03.26 - ErcanOPAK comment on .NET Core: Use IHostedService for Background Tasks

⏰ Long-Running Tasks in ASP.NET Core Need scheduled jobs? Background processing? Email queue? IHostedService runs tasks in background without blocking requests. Basic Background Service public class EmailQueueService : BackgroundService { private readonly ILogger _logger; private readonly IServiceProvider _services; public EmailQueueService( ILogger logger, IServiceProvider services) { _logger = logger; _services = services; } protected override async […]

Read More
Asp.Net Core

.NET Core Background Services: Running Tasks Without Blocking Your API

- 23.02.26 | 23.02.26 - ErcanOPAK comment on .NET Core Background Services: Running Tasks Without Blocking Your API

⏰ The Slow Endpoint Problem User uploads 100MB file. Your API processes it… for 45 seconds. Request times out. User refreshes. Uploads again. Your server? On fire. 🔥 Background Services: The Fire-and-Forget Pattern ❌ Blocking the Request (Bad) [HttpPost(“upload”)] public async Task Upload(IFormFile file) { // Save file await SaveFileAsync(file); // 2 seconds // Generate […]

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