SimpleThreadMonitor 1.0.2.1

Simple C# Mutex.

Requires NuGet 2.12 or higher.

Install-Package SimpleThreadMonitor -Version 1.0.2.1
dotnet add package SimpleThreadMonitor --version 1.0.2.1
<PackageReference Include="SimpleThreadMonitor" Version="1.0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleThreadMonitor --version 1.0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

SimpleThreadMonitor

SimpleThreadMonitor provides simple mutex feature.

using SimpleThreadMonitor;

object lock = new object();

SimpleMutex.Lock(lock, () => 
{
  // Do something
});

Implementaion

public static class SimpleMutex
{
  public static void Lock(object Object, Action Process, Action<Exception> ExceptionCallback = null, bool ReleaseLockBeforeExceptionCallback = false)
  {
    if (Object != null && Process != null)
    {
      try
      {
        Monitor.Enter(Object);
        {
          Process();
        }
        Monitor.Exit(Object);
      }
      catch (Exception Exception)
      {
        if (ReleaseLockBeforeExceptionCallback)
        {
          Monitor.Exit(Object);
        }

        try { ExceptionCallback?.Invoke(Exception); }
        catch { }
        
        if (!ReleaseLockBeforeExceptionCallback)
        {
          Monitor.Exit(Object);
        }
      }
    }
  }
}

Note

Since this project is only for simple mutex, there is NO plan to provide any other complex features.

SimpleThreadMonitor

SimpleThreadMonitor provides simple mutex feature.

using SimpleThreadMonitor;

object lock = new object();

SimpleMutex.Lock(lock, () => 
{
  // Do something
});

Implementaion

public static class SimpleMutex
{
  public static void Lock(object Object, Action Process, Action<Exception> ExceptionCallback = null, bool ReleaseLockBeforeExceptionCallback = false)
  {
    if (Object != null && Process != null)
    {
      try
      {
        Monitor.Enter(Object);
        {
          Process();
        }
        Monitor.Exit(Object);
      }
      catch (Exception Exception)
      {
        if (ReleaseLockBeforeExceptionCallback)
        {
          Monitor.Exit(Object);
        }

        try { ExceptionCallback?.Invoke(Exception); }
        catch { }
        
        if (!ReleaseLockBeforeExceptionCallback)
        {
          Monitor.Exit(Object);
        }
      }
    }
  }
}

Note

Since this project is only for simple mutex, there is NO plan to provide any other complex features.

Release Notes

Add .Net core 2.0, 3.0 support.

  • .NETCoreApp 2.0

    • No dependencies.
  • .NETCoreApp 3.0

    • No dependencies.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SimpleThreadMonitor:

Package Downloads
EmitterSharp
C# implementation of Emitter in JavaScript module. See https://github.com/component/emitter for details.
EngineIOSharp
C# implementation of Engine.IO protocol revision 3 client and server.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.2.1 88 5/11/2020