Denxorz.Latch 1.0.2

Pattern to avoid a part of code being called.

Install-Package Denxorz.Latch -Version 1.0.2
dotnet add package Denxorz.Latch --version 1.0.2
<PackageReference Include="Denxorz.Latch" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Denxorz.Latch --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Denxorz.Latch, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Denxorz.Latch as a Cake Addin
#addin nuget:?package=Denxorz.Latch&version=1.0.2

// Install Denxorz.Latch as a Cake Tool
#tool nuget:?package=Denxorz.Latch&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Latch

.Build status Coverage Status NuGet License

What does it do?

Latch makes sure that a piece of code is not executed when another piece of code is executing.

This package is based on the following articles:

Examples

// Remove the event handler for the moment
someComboBox.SelectedIndexChanged -= someHandler;

// do something that would probably make someComboBox fire the SelectedIndexChanged event

// Put the event handler back
someComboBox.SelectedIndexChanged += someHandler;

This example shows a common WinForms problem which can be solved with a latch.

// Declare the Latch as field: Latch someComboBoxLatch = new Latch();

someComboBoxLatch.RunInsideLatch(() =>
{
    // do something that would probably make someComboBox fire the SelectedIndexChanged event
});

Surrounding the critical code by the latch makes sure it is only executed once. Recursive calls and StackOverflows can be avoided.

// Declare the FullLatch as field: FullLatch someLatch = new FullLatch();

someLatch.LatchAndRun(() =>
{
    // do something and make sure the latch is set
});

someLatch.RunIfNotLatched(() =>
{
    // do something that should only run when not latched
});

This way you will have full control over the latch, and you can choose which parts latch
and which parts are only run if not latched.

Tools and Products Used

Versions & Release Notes

version 1.0.2: Added .NET 5.0

version 1.0.1: Added .NET standard 2.0

version 1.0.0: First version (.NET Framework 4.5.2)

Latch

.Build status Coverage Status NuGet License

What does it do?

Latch makes sure that a piece of code is not executed when another piece of code is executing.

This package is based on the following articles:

Examples

// Remove the event handler for the moment
someComboBox.SelectedIndexChanged -= someHandler;

// do something that would probably make someComboBox fire the SelectedIndexChanged event

// Put the event handler back
someComboBox.SelectedIndexChanged += someHandler;

This example shows a common WinForms problem which can be solved with a latch.

// Declare the Latch as field: Latch someComboBoxLatch = new Latch();

someComboBoxLatch.RunInsideLatch(() =>
{
    // do something that would probably make someComboBox fire the SelectedIndexChanged event
});

Surrounding the critical code by the latch makes sure it is only executed once. Recursive calls and StackOverflows can be avoided.

// Declare the FullLatch as field: FullLatch someLatch = new FullLatch();

someLatch.LatchAndRun(() =>
{
    // do something and make sure the latch is set
});

someLatch.RunIfNotLatched(() =>
{
    // do something that should only run when not latched
});

This way you will have full control over the latch, and you can choose which parts latch
and which parts are only run if not latched.

Tools and Products Used

Versions & Release Notes

version 1.0.2: Added .NET 5.0

version 1.0.1: Added .NET standard 2.0

version 1.0.0: First version (.NET Framework 4.5.2)

  • .NETFramework 4.5.2

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net5.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 History

Version Downloads Last updated
1.0.2 103 2/6/2021
1.0.1 309 4/5/2019
1.0.0 760 11/25/2016