Pustalorc.AsyncThreadingUtils 1.1.0

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

// Install Pustalorc.AsyncThreadingUtils as a Cake Tool
#tool nuget:?package=Pustalorc.AsyncThreadingUtils&version=1.1.0                

Async Threading Utils NuGet

Library that adds a BackgroundWorker and TaskQueue with Async support.

Installation & Usage

Before you begin, please make sure that your current solution has installed the nuget package of this library.
You can find this package here.


Background Worker Usage

There are 2 ways to create the background worker.
You can use object initialization on BackgroundWorkerWithTasks as follows:

Worker = new BackgroundWorkerWithTasks
{
    FunctionToExecute = ExecuteWork,
    ExceptionRaised = ExceptionRaised,
    Repeating = true,
    StartThrowsExceptions = false,
    StopThrowsExceptions = false
};

Or use the constructor which takes all the same options as parameters:

Worker = new BackgroundWorkerWithTasks(ExecuteWork, ExceptionRaised, true, false, false);

From here, simply start the worker with Worker.Start() when you want it to start doing work, and the ExecuteWork method will be executed on a separate thread.

If later you wish to stop a repeating worker, or a worker that is doing heavy work in the middle of execution, simply call Worker.Stop() for it to stop and the code to wait for it to fully finalize, or Worker.NonBlockingStop() to not wait for the worker to fully stop.

If you use NonBlockingStop and still wish to know when exactly the worker has finished, the event Worker.WorkerExecutionCompleted is available


Task Queue Usage

Just like the background worker, the task queue can be created in 2 ways.
You can use object initialization on TaskQueue as follows:

Queue = new TaskQueue
{
    ExceptionRaised = ExceptionRaised,
    DelayOnEmptyQueue = 5000,
    DelayOnQueueNotReady = 1000,
    DelayOnItemNotReady = 25,
    DelayOnItemExecuted = 1,
    StartThrowsExceptions = false,
    StopThrowsExceptions = false
};

Or use the constructor which takes all the same options as parameters:

Queue = new TaskQueue(ExceptionRaised, 5000, 1000, 25, 1, false, false);

From here, simply start the queue with Queue.Start() when you want it to start processing the queue.
Note that the queue will not simply run once and then stop when its empty, it will continuously run, but wait the configured DelayOnEmptyQueue before trying again should the queue be empty.
You can inherit the TaskQueue class and modify this behaviour if you so wish.

With the queue running, you can queue tasks to be executed with 2 methods:
Either QueueAnonymousTask which allows to queue lambda expressions or full methods without defining a class for the task, or QueueTask which allows to queue specific queueable tasks that you create.

If you wish to see how to create a queueable task, see the QueuedAnonymousTask for an example.
The basics of it however is that an Execute method is implemented that will only run if the task isn't cancelled and its UnixTimeStampToExecute has been surpassed by the current unix timestamp (in milliseconds).

You can stop the queue at any time from processing by running Queue.Stop() or Queue.NonBlockingStop().
Both function similarly to the background worker methods.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pustalorc.AsyncThreadingUtils:

Package Downloads
Pustalorc.AsyncTaskDispatcher

A RocketMod 4 plugin that adds an Asynchronous Task Dispatcher for asyncrhonously dispatching tasks into a second thread, and a static class for access like Rocketmod.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 132 8/12/2024
1.1.0 253 4/10/2023
1.0.0 206 12/8/2022

Added additional delay settings to alleviate high cpu usage.