Linger.Background 1.0.0

dotnet add package Linger.Background --version 1.0.0
                    
NuGet\Install-Package Linger.Background -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Linger.Background" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.Background" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Linger.Background" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Linger.Background --version 1.0.0
                    
#r "nuget: Linger.Background, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Linger.Background@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Linger.Background&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Linger.Background&version=1.0.0
                    
Install as a Cake Tool

Linger.Background

一个轻量级的.NET后台任务处理库。

介绍

Linger.Background为.NET开发者提供了简单的工具和扩展,用于在.NET应用程序中管理和执行基本的后台任务。

功能

  • 基础后台任务队列
  • 简单的工作者处理机制
  • 任务取消支持
  • 与.NET依赖注入集成

使用示例

// 注册服务
public void ConfigureServices(IServiceCollection services)
{
    // 根据实际项目中的扩展方法来注册Background服务
    services.AddHostedService<QueuedHostedService>();
    services.AddSingleton<IBackgroundTaskQueue>(ctx =>
    {
        //if (!int.TryParse(hostContext.Configuration["QueueCapacity"], out var queueCapacity))
        var queueCapacity = 100;
        return new BackgroundTaskQueue(queueCapacity);
    });
}

// 使用后台任务队列
public class SampleService
{
    private readonly IBackgroundTaskQueue _taskQueue;
    
    public SampleService(IBackgroundTaskQueue taskQueue)
    {
        _taskQueue = taskQueue;
    }
    
    public async Task EnqueueWorkItem()
    {
        // 注意: Lambda 接收两个参数 (IServiceProvider, CancellationToken)
        await _taskQueue.QueueBackgroundWorkItemAsync(async (serviceProvider, token) =>
        {
            // 可以从 serviceProvider 获取服务
            var logger = serviceProvider.GetRequiredService<ILogger<SampleService>>();
            
            // 执行后台工作,支持取消
            await Task.Delay(1000, token);
            logger.LogInformation("后台任务执行完成");
        });
    }
    
    // 支持外部取消令牌
    public async Task EnqueueWorkItemWithCancellation(CancellationToken cancellationToken)
    {
        await _taskQueue.QueueBackgroundWorkItemAsync(
            async (serviceProvider, token) =>
            {
                // 执行后台工作
                await Task.Delay(1000, token);
            },
            cancellationToken); // 可选的取消令牌参数
    }
}

安装

Package Manager命令行

PM> Install-Package Linger.Background

.NET CLI命令行

> dotnet add package Linger.Background
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 280 11/12/2025
1.0.0-preview2 142 11/6/2025
1.0.0-preview1 151 11/5/2025
0.9.9 137 10/16/2025
0.9.8 141 10/14/2025
0.9.7-preview 132 10/13/2025
0.9.6-preview 117 10/12/2025
0.9.5 117 9/28/2025
0.9.4-preview 137 9/25/2025
0.9.3-preview 161 9/22/2025
0.9.1-preview 279 9/16/2025
0.9.0-preview 92 9/12/2025
0.8.5-preview 202 8/31/2025
0.8.4-preview 319 8/25/2025
0.8.3-preview 163 8/20/2025
0.8.2-preview 208 8/4/2025
0.8.1-preview 132 7/30/2025
0.8.0-preview 569 7/22/2025
0.7.2 187 6/3/2025
0.7.1 190 5/21/2025
0.7.0 181 5/19/2025
0.6.0-alpha 188 4/28/2025
0.5.0-alpha 199 4/10/2025
0.4.0-alpha 186 4/1/2025
0.3.3-alpha 198 3/19/2025
0.3.2-alpha 185 3/17/2025
0.3.1-alpha 175 3/16/2025
0.3.0-alpha 244 3/6/2025