using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace HMC
{
public class SafeGuardLock:IDisposable
{
public SafeGuardLock(Mutex nodelockfrom)
{
nodelock = nodelockfrom;
}
public void AcquireLock()
{
nodelock.WaitOne();
lockheld = true;
}
public Mutex nodelock = null;
private bool lockheld = false;
public void Dispose()
{
if (lockheld)
{
nodelock.ReleaseMutex();
}
}
}
}
using (SafeGuardLock safelock = new SafeGuardLock(nodelock))
{
safelock.AcquireLock();
}