Multithreading_Library 1.3.0

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

Multithreading_Library

This library provides utilities to handle various multithreading scenarios in .NET applications. It contains the following classes:

  1. OneWriteMultiRead: This class allows an object to be read from multiple threads at the same time but only updated from one thread at a time. This helps to ensure data integrity when working with shared resources across multiple threads.
// Example usage
OneWrite_MultiRead<decimal> sharedDecimal = new OneWrite_MultiRead<decimal>(100);

/// Reader threads
decimal t = sharedDecimal.Value;

// writer thread
sharedDecimal.Value = VALUE1;
  1. IDLocks: This class provides locks that are accessible through a dictionary. This allows specific tasks, names, or other entities to be locked individually, enabling finer control over thread synchronization.
// Example usage
IDLocks<int> idLocks = new IDLocks<int>();
var lockObject = idLocks.ObtainLockObject(5);
  1. RequestIDGenerator this class returns an incremental, threadsafe id which can be used to identify requests. EG for a websocket. The function rolls over to 0 at int.MaxValue
// Example usage
RequestIDGenerator idGenerator = new RequestIDGenerator();
int id = idGenerator.GetNextRequestId()
  1. AsyncHelper: This class provides utilities to run an asynchronous Task and wait for the result in a synchronous method. It should be used with caution as it can lead to potential deadlocks. Whenever possible, prefer keeping async code all the way up the call stack.
// Example usage
int parameter = 5;
int result = AsyncHelper.RunSync(async () => await SomeAsyncMethod(parameter));
  1. Caching: The library includes examples of lightweight caching mechanisms.
    • LazyCache\<T\>: A simple cache that holds a value for a specified timespan. After the timespan expires, it returns null or default.

      // Example usage
      LazyCache<int?> numberCache = new (TimeSpan.FromMinutes(5)); // values are valid for 5 Minutes
      numberCache.Value = 42; // Setting a value
      int? cachedNumber = numberCache.Value; // Retrieving the value
      if (cachedNumber == null) // set new value if cache has expired
          cachedNumber = FetchReason("Life");
      
    • LazyCacheDictionary\<TKey, TValue\>: A thread-safe, lazy-loading cache dictionary with expiration for each key. It supports automatic cleanup of expired entries.

      // Example usage
      
      // individual item validity time = 5 Minutes
      // cache cleanup interval = 1 Hour
      LazyCacheDictionary<string, int?> dictionaryCache = new (TimeSpan.FromMinutes(5), TimeSpan.FromHours(1));
      
      dictionaryCache.Set("key1", 100); // Adding a value
      int? value = dictionaryCache.Get("key1"); // Retrieving a value
      if (value == null) // set new value if cache has expired
          dictionaryCache.Set("Life", 42);
      
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 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 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 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.  net10.0 was computed.  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.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Multithreading_Library:

Package Downloads
Chia-Client-API

CHIA-RPC is a C# Nuget library that allows developers to easily communicate with the Chia client. It provides a wrapper for making requests, sending transactions, and minting, making it a versatile tool for interacting with the Chia blockchain. With CHIA-RPC, you can easily integrate Chia functionality into your C# projects.

StringHelper.Net

a lightweight library with some arbitrary string algorhythms for cleanup, converting, comparing and file interaction

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.5.2 156 4/11/2025
2.5.1 192 4/2/2025
2.4.6 116 1/14/2025
2.4.5 125 11/27/2024
2.4.4 123 11/13/2024
2.4.2 138 7/16/2024
2.4.1 168 4/10/2024
2.4.0 136 4/9/2024
2.3.0 149 4/8/2024
2.2.0 146 4/4/2024
2.1.1 148 4/4/2024
2.1.0 142 4/4/2024
2.0.0 146 3/27/2024
1.9.0 162 3/15/2024
1.8.0 171 1/19/2024
1.7.0 134 1/19/2024
1.6.0 176 1/4/2024
1.5.0 175 12/13/2023
1.4.0 147 12/12/2023
1.3.0 159 12/5/2023
1.2.1 230 12/1/2023
1.2.0 140 12/1/2023
1.1.1 199 7/4/2023
1.1.0 188 7/4/2023
1.0.1 322 1/25/2023
1.0.0 342 1/9/2023

1.3.0
- added LazyCache, a minimal cache implementation
- added LazyCacheDictionary, a minimal caching solution for dictionary values

1.2.1
- Added RequestIDGenerator to obtain short term unique identifiers
- added .Net 8.0