Shane32.AsyncResetEvents 3.1.2

dotnet add package Shane32.AsyncResetEvents --version 3.1.2                
NuGet\Install-Package Shane32.AsyncResetEvents -Version 3.1.2                
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="Shane32.AsyncResetEvents" Version="3.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Shane32.AsyncResetEvents --version 3.1.2                
#r "nuget: Shane32.AsyncResetEvents, 3.1.2"                
#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 Shane32.AsyncResetEvents as a Cake Addin
#addin nuget:?package=Shane32.AsyncResetEvents&version=3.1.2

// Install Shane32.AsyncResetEvents as a Cake Tool
#tool nuget:?package=Shane32.AsyncResetEvents&version=3.1.2                

Shane32.AsyncResetEvents

NuGet Coverage Status

AsyncAutoResetEvent

The methods match similar methods on AutoResetEvent:

  • void Set(bool backgroundThread = false)
  • Task WaitAsync(CancellationToken cancellationToken = default)
  • Task<bool> WaitAsync(int millisecondsTimeout, CancellationToken cancellationToken = default)
  • Task<bool> WaitAsync(TimeSpan timeout, CancellationToken cancellationToken = default)

Calling Set will execute waiting task continuation functions on the same thread by default. Setting the backgroundThread parameter will schedule them through the task scheduler.

WaitAsync supports a timeout and cancellation token. If the cancellation token is triggered before the reset event is signaled, a OperationCanceledException is throw. If the timeout occurs, false is returned. If the reset event is signaled, true is returned.

As an automatic reset event, calling WaitAsync will reset the signal. Note that a queue is maintained, and calling Set will only allow a single waiting task continuation function to execute. If no task continuation functions are waiting, calling Set one or more times will allow only the next call to WaitAsync to execute. Additional calls to WaitAsync will wait for an additional call to Set.

AsyncManualResetEvent

The methods are identical to above, with the addition of the Reset method.

  • void Set(bool backgroundThread = false)
  • void Reset()
  • Task WaitAsync(CancellationToken cancellationToken = default)
  • Task<bool> WaitAsync(int millisecondsTimeout, CancellationToken cancellationToken = default)
  • Task<bool> WaitAsync(TimeSpan timeout, CancellationToken cancellationToken = default)

As a manual reset event, calling WaitAsync will wait until the event is signaled. Signaling the event with Set will result in the event staying signaled until Reset is called. As such, you may call WaitAsync any number of times on a signaled event and execution will continue. If the reset event is not signaled, you may call WaitAsync any number of times and they will all wait until Set is called before executing.

AsyncMessagePump

Synchronizes execution of a sequence of asynchronous tasks. This maintains execution order while allowing tasks to be posted asynchronously to the queue. The callback delegate may be an asynchronous or synchronous delegate. Messages may be posted directly or an asynchronous operation that returns a message may be posted to the queue. Regardless, execution order is maintained as of the point in time that Post was called, and the callback is never run on multiple threads at once. If an asynchronous operation was posted and it throws an exception, or if the callback throws an exception, the exception is handled by the HandleErrorAsync protected method, which can be overridden by a user in a derived class. DrainAsync is provided to wait for pending messages to be processed.

Note that the ExecutionContext is captured during the Post call and restored while the callback (and/or the error handler) is executed.

Constructors:

  • AsyncMessagePump(Func<T, Task> callback)
  • AsyncMessagePump(Action<T> callback)

Public methods:

  • void Post(T message)
  • void Post(Task<T> messageTask)
  • Task DrainAsync()

Public properties:

  • int Count { get; }

Protected methods:

  • Task HandleErrorAsync(Exception exception)

AsyncDelegatePump

Synchronizes executes of asynchronous delegates. Queued delegates executes in the order that they were queued with a call to Post. This class is derived from AsyncMessagePump; see above for further details. Also included is SendAsync, which will queue an asynchronous delegate and return its result after it executes (in its turn). Any further code after awaiting a Task returned by SendAsync will not prevent additional delegates in the queue from executing. SendAsync also accepts an optional timeout and cancellation token parameter. If the timeout expires before the delegate is executed, a TimeoutException is thrown and the delegate is not executed. Similarly, if the cancellation token is triggered before the delegate is executed, a OperationCanceledException is thrown and the delegate is not executed.

Note that the ExecutionContext is captured during the call to SendAsync and restored while the delegate is executed.

Public methods:

  • void Post(Func<Task> message)
  • Task SendAsync(Func<Task> action)
  • Task SendAsync(Func<Task> action, CancellationToken token)
  • Task SendAsync(Func<Task> action, TimeSpan timeout, CancellationToken token = default)
  • Task<T> SendAsync<T>(Func<Task<T>> action)
  • Task<T> SendAsync<T>(Func<Task<T>> action, CancellationToken token)
  • Task<T> SendAsync<T>(Func<Task<T>> action, TimeSpan timeout, CancellationToken token = default)
  • Task DrainAsync()

Public properties:

  • int Count { get; }

Protected methods:

  • Task HandleErrorAsync(Exception exception) (not needed when SendAsync is used)

Credits

Glory to Jehovah, Lord of Lords and King of Kings, creator of Heaven and Earth, who through his Son Jesus Christ, has reedemed me to become a child of God. -Shane32

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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 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 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. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.0 is compatible.  netstandard1.1 was computed.  netstandard1.2 was computed.  netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wp8 was computed.  wp81 was computed.  wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 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.
  • .NETStandard 1.0

  • .NETStandard 1.3

  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.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
3.1.2 2,038 7/18/2024
3.1.1 6,180 1/9/2024
3.1.0 1,184 10/19/2023
3.0.0 6,471 7/19/2023
2.4.1 1,160 4/19/2023
2.4.0 190 4/19/2023
2.3.0 4,583 12/6/2022
2.2.0 348 12/4/2022
2.0.0 4,537 3/15/2022
1.0.1 433 3/11/2022
1.0.0 453 3/11/2022 1.0.0 is deprecated because it has critical bugs.