MultiThread.CommunityToolKit 1.0.1

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

// Install MultiThread.CommunityToolKit as a Cake Tool
#tool nuget:?package=MultiThread.CommunityToolKit&version=1.0.1                

MultiThread.CommunityToolKit社区工具包

并行处理快速工具包

  1. 帮助您在编写快速编写并行算法

Definition

Namespace: MultiThread.CommunityToolKit Assembly: MultiThread.CommunityToolKit.dll

Examples

// See https://aka.ms/new-console-template for more information

using Microsoft.Extensions.Logging;
using MultiThread.CommunityToolKit;
using Stopwatch.CommunityToolKit;

Console.WriteLine("Hello, World!");
var logger = new MyLogger();
logger.LogInformation("haha");

var list = new List<int>();
for (int i = 0; i < 100; i++)
{
 list.Add(i);   
}

StopwatchJobHelper.Do(() =>
{
    list.ForEach(
        r =>
        {
            Console.WriteLine(r);
            Thread.Sleep(100);//模拟每个人物耗时100ms
        }
        );
   
}, logger, "单线程");


StopwatchJobHelper.Do(() =>
{
    var newList = MultiThreadJobHelper.Do(3, list, (r) =>
    {
        r.ToList().ForEach(
            r =>
            {
                Console.WriteLine(r);
                Thread.Sleep(100);//模拟每个人物耗时100ms
            }
        );
        return r.ToList();
    });
}, logger, "多线程");

Console.ReadLine();

class MyLogger : ILogger
{
    public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
    {
        if (logLevel==LogLevel.Information)
        {
            Console.WriteLine(state);
        }
       
    }

    public bool IsEnabled(LogLevel logLevel)
    {
        throw new NotImplementedException();
    }

    public IDisposable BeginScope<TState>(TState state)
    {
        throw new NotImplementedException();
    }
}

测试效果

100个任务每个任务耗时100ms开启3线程是单线程效率三倍

alternate text is missing from this package README image

Release Note

Version Updates
1.0.1 修复空指针问题
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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.
  • net6.0

    • No dependencies.

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.2 422 9/16/2022
1.0.1 391 8/26/2022
1.0.0 482 7/7/2022 1.0.0 is deprecated because it has critical bugs.