Linger.Background 0.3.2-alpha

This is a prerelease version of Linger.Background.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Linger.Background --version 0.3.2-alpha
                    
NuGet\Install-Package Linger.Background -Version 0.3.2-alpha
                    
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="0.3.2-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.Background" Version="0.3.2-alpha" />
                    
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 0.3.2-alpha
                    
#r "nuget: Linger.Background, 0.3.2-alpha"
                    
#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.
#addin nuget:?package=Linger.Background&version=0.3.2-alpha&prerelease
                    
Install Linger.Background as a Cake Addin
#tool nuget:?package=Linger.Background&version=0.3.2-alpha&prerelease
                    
Install Linger.Background as a Cake Tool

Linger.Background

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

介绍

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

功能

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

使用示例

// 注册服务
public void ConfigureServices(IServiceCollection services)
{
    // 根据实际项目中的扩展方法来注册Background服务
    services.AddHostedService<QueuedHostedService>();
    builder.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()
    {
        await _taskQueue.QueueBackgroundWorkItemAsync(async token =>
        {
            // 执行后台工作
            await Task.Delay(1000, token);
        });
    }
}

安装

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. 
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
0.5.0-alpha 119 4/10/2025
0.4.0-alpha 116 4/1/2025
0.3.3-alpha 119 3/19/2025
0.3.2-alpha 112 3/17/2025
0.3.1-alpha 104 3/16/2025
0.3.0-alpha 172 3/6/2025