代码拉取完成,页面将自动刷新
using System;
using System.Globalization;
using System.Threading;
namespace csscript
{
internal interface ISystemWideLock : IDisposable
{
bool Wait(int millisecondsTimeout);
void Release();
}
internal class WinSystemWideLock : ISystemWideLock, IDisposable
{
Mutex mutex;
public WinSystemWideLock(string name)
{
mutex = new Mutex(false, name);
}
public bool Wait(int millisecondsTimeout)
{
//even if locked Mutex will handle it. It will return immediately
return mutex.WaitOne(millisecondsTimeout, false);
}
public void Release()
{
try { mutex.ReleaseMutex(); }
catch { }
}
public void Dispose()
{
Release();
try { mutex.Close(); }
catch { }
}
}
internal class LinuxSystemWideLock : ISystemWideLock, IDisposable
{
Mono.Unix.FileMutex mutex;
public LinuxSystemWideLock(string file, string context)
{
mutex = new Mono.Unix.FileMutex(file, context);
}
public bool Wait(int millisecondsTimeout)
{
return mutex.Wait(millisecondsTimeout);
}
public void Dispose()
{
Release();
}
public void Release()
{
try { mutex.Release(); }
catch { }
}
}
internal class SystemWideLock : ISystemWideLock, IDisposable
{
ISystemWideLock mutex;
bool locked = false;
public SystemWideLock(string file, string context)
{
bool isLinux = (Environment.OSVersion.Platform == PlatformID.Unix);
if (isLinux)
{
mutex = new LinuxSystemWideLock(file, context);
}
else
{
file = file.ToLower(CultureInfo.InvariantCulture);
mutex = new WinSystemWideLock("" + context + "." + CSSUtils.GetHashCodeEx(file));
}
}
public bool Wait(int millisecondsTimeout)
{
if (!locked)
locked = mutex.Wait(millisecondsTimeout);
return locked;
}
public void Release()
{
if (locked)
{
mutex.Release();
locked = false;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
mutex.Dispose();
disposed = true;
}
~SystemWideLock()
{
Dispose(false);
}
bool disposed = false;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。