mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
Reverted the global app lock for the db #2750
This commit is contained in:
parent
13a73020e5
commit
439dc395d0
12 changed files with 10 additions and 57 deletions
|
@ -1,39 +0,0 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Nito.AsyncEx;
|
||||
|
||||
namespace Ombi.Helpers
|
||||
{
|
||||
public static class GlobalMutex
|
||||
{
|
||||
public static async Task<T> Lock<T>(Func<Task<T>> func)
|
||||
{
|
||||
const string mutexId = "Global\\OMBI";
|
||||
using (var mutex = new Mutex(false, mutexId, out _))
|
||||
{
|
||||
var hasHandle = false;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
hasHandle = mutex.WaitOne(5000, false);
|
||||
if (hasHandle == false)
|
||||
throw new TimeoutException("Timeout waiting for exclusive access");
|
||||
}
|
||||
catch (AbandonedMutexException)
|
||||
{
|
||||
hasHandle = true;
|
||||
}
|
||||
|
||||
return await func();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (hasHandle)
|
||||
mutex.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue