Linger.Background 1.1.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Linger.Background --version 1.1.0
                    
NuGet\Install-Package Linger.Background -Version 1.1.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.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.Background" Version="1.1.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.1.0
                    
#r "nuget: Linger.Background, 1.1.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.1.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.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Linger.Background&version=1.1.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.2.0-preview 25 3/29/2026
1.1.0 97 2/4/2026
1.0.3-preview 103 1/9/2026
1.0.2-preview 94 1/8/2026
1.0.0 295 11/12/2025
1.0.0-preview2 156 11/6/2025
1.0.0-preview1 168 11/5/2025
0.9.9 155 10/16/2025
0.9.8 160 10/14/2025
0.9.7-preview 152 10/13/2025
0.9.6-preview 134 10/12/2025
0.9.5 137 9/28/2025
0.9.4-preview 157 9/25/2025
0.9.3-preview 181 9/22/2025
0.9.1-preview 301 9/16/2025
0.9.0-preview 113 9/12/2025
0.8.5-preview 218 8/31/2025
0.8.4-preview 338 8/25/2025
0.8.3-preview 188 8/20/2025
0.8.2-preview 227 8/4/2025
Loading failed