GithubHelp home page GithubHelp logo

qaz734913414 / asyncworkercollection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnet-campus/asyncworkercollection

1.0 0.0 0.0 153 KB

高性能的多线程异步工具库。A collection of tools that support asynchronous methods and support high-performance multithreading.

License: MIT License

C# 100.00%

asyncworkercollection's Introduction

dotnetCampus.AsyncWorkerCollection

中文

Build NuGet

A collection of tools that support asynchronous methods and support high-performance multithreading.

Install NuGet package

Two different libraries are provided for installation.

Install the traditionary NuGet Dll library

.NET CLI:

dotnet add package dotnetCampus.AsyncWorkerCollection

PackageReference:

<PackageReference Include="dotnetCampus.AsyncWorkerCollection" Version="1.2.1" />

Install the SourceYard NuGet source code

.NET CLI:

dotnet add package dotnetCampus.AsyncWorkerCollection.Source --version 1.2.1

PackageReference:

<PackageReference Include="dotnetCampus.AsyncWorkerCollection.Source" Version="1.2.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

Usage

AsyncQueue

An asynchronous queue that supports multiple threads

Create a queue:

  var asyncQueue = new AsyncQueue<FooTask>();

Add task to queue:

  asyncQueue.Enqueue(new FooTask());

Waiting for the task to dequeue:

  var fooTask = await asyncQueue.DequeueAsync();

The advantage of AsyncQueue over Channel is that it supports .NET Framework 45 and simple

DoubleBufferTask

DoubleBufferTask supports multi-threaded fast input data and single-threaded batch processing of data, and supports waiting for buffer execution to complete

var doubleBufferTask = new DoubleBufferTask<Foo>(list =>
{
    // Method to perform batch List<Foo> tasks
    // The incoming delegate will be called when there is data in the DoubleBufferTask, and it means that there is at least one element in the list
});

// Multiple other threads call this code to add the task data
doubleBufferTask.AddTask(new Foo());

// After the business code is completed, call the Finish method to indicate that no more tasks are added
// This Finish method is not thread-safe
doubleBufferTask.Finish();

// Other threads can call WaitAllTaskFinish to wait for the completion of all task data in DoubleBufferTask
// It will return after be Finish method be called and the all the task data be handled
await doubleBufferTask.WaitAllTaskFinish();

AsyncAutoResetEvent

Asynchronous version of AutoResetEvent lock

AsyncAutoResetEvent is functionally the same as AutoResetEvent, except that WaitOne is replaced with WaitOneAsync to support asynchronous waiting

AsyncManualResetEvent

Asynchronous version of ManualResetEvent lock

AsyncManualResetEvent is functionally the same as ManualResetEvent, except that WaitOne is replaced with WaitOneAsync to support asynchronous waiting

Benchmark

See Benchmark.md

Contributing

PRs Welcome

If you would like to contribute, feel free to create a Pull Request, or give us Bug Report.

asyncworkercollection's People

Contributors

github-actions[bot] avatar h82258652 avatar handsome08 avatar kkwpsv avatar lindexi avatar walterlv avatar xinyuehtx avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.