{"id":20762544,"url":"https://github.com/twentyfourminutes/backgroundqueue","last_synced_at":"2025-07-15T04:09:36.752Z","repository":{"id":44341338,"uuid":"219012313","full_name":"TwentyFourMinutes/BackgroundQueue","owner":"TwentyFourMinutes","description":"An easy way to process tasks which do not block the current Action","archived":false,"fork":false,"pushed_at":"2022-07-09T09:53:34.000Z","size":46,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T07:08:43.277Z","etag":null,"topics":["asp-net-core","background-thread","backgroundqueue","csharp","thread-safety"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TwentyFourMinutes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-01T15:28:43.000Z","updated_at":"2024-07-30T00:45:15.000Z","dependencies_parsed_at":"2022-07-16T02:46:20.415Z","dependency_job_id":null,"html_url":"https://github.com/TwentyFourMinutes/BackgroundQueue","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/TwentyFourMinutes/BackgroundQueue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwentyFourMinutes%2FBackgroundQueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwentyFourMinutes%2FBackgroundQueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwentyFourMinutes%2FBackgroundQueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwentyFourMinutes%2FBackgroundQueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TwentyFourMinutes","download_url":"https://codeload.github.com/TwentyFourMinutes/BackgroundQueue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwentyFourMinutes%2FBackgroundQueue/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265402611,"owners_count":23759192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net-core","background-thread","backgroundqueue","csharp","thread-safety"],"created_at":"2024-11-17T10:36:17.190Z","updated_at":"2025-07-15T04:09:36.700Z","avatar_url":"https://github.com/TwentyFourMinutes.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BackgroundQueue\n\n\u003ca href=\"https://www.nuget.org/packages/BackgroundQueue\"\u003e\u003cimg alt=\"Nuget\" src=\"https://img.shields.io/nuget/v/BackgroundQueue\"\u003e\u003c/a\u003e \u003ca href=\"https://www.nuget.org/packages/BackgroundQueue\"\u003e\u003cimg alt=\"Nuget\" src=\"https://img.shields.io/nuget/dt/BackgroundQueue\"\u003e\u003c/a\u003e \u003cimg alt=\"GitHub issues\" src=\"https://img.shields.io/github/issues-raw/TwentyFourMinutes/BackgroundQueue\"\u003e\n\nBackgroundQueue is a simple way to queue background Tasks in ASP.Net Core and in .Net in general.\nYou can download BackgroundQueue either from the Nuget Package Manager or from the official [nuget.org](https://www.nuget.org/packages/BackgroundQueue) website.\n\n## About\n\nThis package brings two useful queues with it, which both operate in the Background, that means that they do not block the current Thread. With these queues you can enqueue `Tasks` or `Tickets` which provide even more control. They are also fully thread save and come with a handy `IServiceCollection` extension.\n\n## How to\n\nFirst up, you'll need to download the `BackgroundQueue` nuget package from one of the sources named above. After that you need to decide which one of the queues you need.\n\n### Basic setup \n\n1. In your `ConfigureServices` method you want to add `AddBackgroundTaskQueue` or `AddBackgroundResultQueue` depending on your needs.\n\n   ```c#\n   public void ConfigureServices(IServiceCollection services)\n   {\n      [...]\n   \tservices.AddBackgroundTaskQueue();\n      //Or\n      services.AddBackgroundResultQueue();\n   }\n   ```\n\n2. In your Controller constructor you need to request the queue implementation of your needs, e.g. `IBackgroundTaskQueue`/`IBackgroundResultQueue` .This would look something like the following.\n\n   ```c#\n   public class HomeController : Controller\n   {\n   \tprivate readonly IBackgroundTaskQueue _taskQueue;\n      //Or\n   \tprivate readonly IBackgroundResultQueue _resultQueue;\n       \n   \tpublic DashboardController(IBackgroundTaskQueue taskQueue\n   \t\t\t\t\t\t\t         //Or\n   \t\t\t\t\t\t\t         IBackgroundResultQueue resultQueue)\n   \t{\n   \t\t_taskQueue = taskQueue;\n   \t\t//Or\n   \t\t_resultQueue = resultQueue;\n   \t}\n   }\n   ```\n\n3. In any Action you can now consume any of those queues and start enqueuing items.\n\n   ```c#\n   public async Task\u003cIActionResult\u003e Index()\n   {\n   \t_taskQueue.Enqueue(async token =\u003e\n   \t{\n   \t   await EmailSender.SendEmailAsync(\"Somone visited our website!\");\n   \t});   // Will return immediately.\n       \n       //Or\n       \n      await _backgroundQueue.ProcessInQueueAsync(async token =\u003e\n   \t{\n         // I need to wait for any other items in this queue first!\n   \t});   // Will continue after all other items, which are in front of it are processed.\n       \n   \treturn View();\n   }\n   ```\n\n   \n\n### BackgroundTaskQueue\n\nThe `BackgroundTaskQueue` is a queue which will enqueue items and immediately return to the current execution. You could use this queue for sending emails.\n\n### BackgroundResultQueue\n\nThe `BackgroundResultQueue` is a queue which will enqueue items and waits until the `Task`/`Ticket` finished processing including the result. You could use this queue, if you want requests to get processed step by step, but still want everything happen asynchronously.\n\n## Notes\n\nIf you feel like something is not working as intended or you are experiencing issues, feel free to create an issue. Also for feature requests just create an issue. For further information feel free to send me a mail to `twenty@translucent.at` or message me on Discord `24_minutes#7496`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwentyfourminutes%2Fbackgroundqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwentyfourminutes%2Fbackgroundqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwentyfourminutes%2Fbackgroundqueue/lists"}