From aa1f2ccf6e119c1b5ec687c1c81646df67a14458 Mon Sep 17 00:00:00 2001 From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:01:23 +0000 Subject: [PATCH] Create InterProcessLock.cs --- Bloxstrap/InterProcessLock.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Bloxstrap/InterProcessLock.cs diff --git a/Bloxstrap/InterProcessLock.cs b/Bloxstrap/InterProcessLock.cs new file mode 100644 index 0000000..e1938e8 --- /dev/null +++ b/Bloxstrap/InterProcessLock.cs @@ -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; + } + } + } +}