mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Create InterProcessLock.cs
This commit is contained in:
parent
d3d134ae0d
commit
aa1f2ccf6e
30
Bloxstrap/InterProcessLock.cs
Normal file
30
Bloxstrap/InterProcessLock.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bloxstrap
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user