Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying MutexSecurity for a named global mutex in .NET Core

Is there a way to pass MutexSecurity to a Mutex in .NET Core (currently still using 2.2, switching to .NET 6 in the future)?

.NET Framework has a constructor accepting this parameter, but it seems to have been removed in .NET Core.

like image 264
Groo Avatar asked Oct 17 '25 02:10

Groo


1 Answers

In .NET 6.0 there is the MutexAcl class:

#if NET6_0_OR_LATER
    using (var mutex = MutexAcl.Create(false, mutexId, out bool createdNew, securitySettings))
#else
    using (var mutex = new Mutex(false, mutexId, out bool createdNew, securitySettings))
#endif

Which is available through the System.Threading.AccessControl nuget package.

The method will throw PlatformNotSupportedException if not on Windows (naturally).

like image 168
Christian.K Avatar answered Oct 19 '25 16:10

Christian.K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!