bloxstrap/Bloxstrap/Utility/InterProcessLock.cs
pizzaboxer 776dbc4097
Draft: new installer system
the beginning of a long arduous cleanup of two years of debt
2024-08-10 13:08:04 +01:00

31 lines
688 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap.Utility
{
public class InterProcessLock : IDisposable
{
public Mutex Mutex { get; private set; }
public bool IsAcquired { get; private set; }
public InterProcessLock(string name, TimeSpan timeout)
{
Mutex = new Mutex(false, "Bloxstrap-" + name);
IsAcquired = Mutex.WaitOne(timeout);
}
public void Dispose()
{
if (IsAcquired)
{
Mutex.ReleaseMutex();
IsAcquired = false;
}
}
}
}