VOOZH about

URL: https://www.nuget.org/packages/Open.Threading.ReadWrite/

⇱ NuGet Gallery | Open.Threading.ReadWrite 3.0.1




👁 Image
Open.Threading.ReadWrite 3.0.1

dotnet add package Open.Threading.ReadWrite --version 3.0.1
 
 
NuGet\Install-Package Open.Threading.ReadWrite -Version 3.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="Open.Threading.ReadWrite" Version="3.0.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Open.Threading.ReadWrite" Version="3.0.1" />
 
Directory.Packages.props
<PackageReference Include="Open.Threading.ReadWrite" />
 
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 Open.Threading.ReadWrite --version 3.0.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Open.Threading.ReadWrite, 3.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.
#:package Open.Threading.ReadWrite@3.0.1
 
 
#: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=Open.Threading.ReadWrite&version=3.0.1
 
Install as a Cake Addin
#tool nuget:?package=Open.Threading.ReadWrite&version=3.0.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Open.Threading.ReadWrite

Useful set of extensions and classes for simplifying and optimizing read-write synchronization with ReaderWriterLockSlim.

👁 GitHub license
👁 100% code coverage
👁 NuGet

Purpose

There are very common but tedious patterns to follow when utilizing a ReaderWriterLockSlim. Some of the more complex but useful patterns involve reading (with or without a read lock) and then if a condition is met, acquiring a write lock before proceeding.

This extension library removes the tediousness of properly acquiring and releasing various locks and provides easy access to timeout values if needed.

Basics


Read

rwLockSlim.Read(() =>
{
 /* do work inside a read lock */
});
using(rwLockSlim.ReadLock())
{
 /* do work inside a read lock */
}
int result = rwLockSlim.Read(() =>
{
 int i;
 /* produce a result inside read lock */
 return i;
});

Write

rwLockSlim.Write(() =>
{
 /* do work inside a read lock */
});
using(rwLockSlim.WriteLock())
{
 /* do work inside a write lock */
}
int result = rwLockSlim.Write(() =>
{
 int i;
 /* produce a result inside write lock */
 return i;
});

Upgradable Read

using(rwLockSlim.UpgradableReadLock())
{
 /* do work inside an upgradable read lock */
 if(condition)
 {
 using(rwLockSlim.WriteLock())
 {
 /* upgraded to a write lock */
 }
 }
}

With Timeouts

These throw a TimeoutException if a lock cannot be acquired within the time specified.


Read

rwLockSlim.Read(1000 /* ms */, () =>
{
 /* do work inside a read lock */
});

or

using(rwLockSlim.ReadLock(1000)) // ms
{
 /* do work inside a read lock */
}

Write

rwLockSlim.Write(1000 /* ms */, () =>
{
 /* do work inside a write lock */
});

or

using(rwLockSlim.WriteLock(1000)) // ms
{
 /* do work inside a write lock */
}

Advanced Examples


WriteConditional

This example demonstrates how to properly query a value before writing with a 1 second timeout.

var actionWasInvoked = rwLockSlim.WriteConditional(1000 /* ms */,
() => /* condition that is queried inside an upgradable read lock */,
() => /* do work inside a write lock */);

ReadWriteConditional

This more advanced example optimizes the process of reading and then writing by first testing the condition within a read lock before attempting with an upgradable read lock.

int result = 0;
bool actionWasInvoked = rwLockSlim.ReadWriteConditional(ref result,
isUpgraded => /* condition that is first queried inside a read lock */,
() =>
{
 int i;
 /* do work inside a write lock */
 return i;
});
Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 is compatible. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Open.Threading.ReadWrite:

Package Downloads
Open.Threading.ReadWriteHelper

A utility for read-write synchronizing by context. Useful for synchronizing collections that are not inherently thread-safe. Reference to Open.Threading.ReadWrite exposes extensions for ReaderWriterLockSlim. Part of the "Open" set of libraries.

LiveStreamingServerNet.StreamProcessor

This package provides the capability to transmux RTMP streams into HLS format, and integrates with FFmpeg for stream processing.

ObservableValue

A class representing a value that when updated (posted) signals changes to observers. Will post current value (if initialized) when subscribing. Synchronized to ensure ordering. Compatible with IObservable<T> and System.Reactive.

Open.AsyncToolkit.KeyValue

Provides foundational building blocks for creating asynchronous key-value stores with robust interfaces, synchronization capabilities, and concurrent access patterns.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Open.Threading.ReadWrite:

Repository Stars
josephnhtam/live-streaming-server-net
A .NET implementation of RTMP live streaming server, supporting HTTP-FLV, WebSocket-FLV, HLS, Kubernetes, cloud storage services integration and more.
Version Downloads Last Updated
3.0.1 27,650 11/14/2024
3.0.0 348 11/14/2024
2.0.3 65,613 3/24/2022
2.0.2 79,443 3/22/2022
2.0.1 1,660 3/22/2022
2.0.0 875 3/22/2022
2.0.0-preview3 1,117 3/21/2022
2.0.0-preview2 1,162 3/21/2022
2.0.0-preview1 625 3/19/2022
1.4.8 5,252 9/29/2021
1.4.5 1,938 7/11/2021
1.4.4 1,101 7/11/2021
1.4.3 2,092 7/7/2021
1.4.0 70,271 7/17/2020
1.3.3 18,662 1/4/2020
1.3.2 20,703 7/4/2019
Loading failed