Skip to content

tomaszzmuda/Xabe.FileLock

Repository files navigation

Xabe.FileLock

Build Status NuGet version GitHub issues GitHub stars GitHub license HitCount

.NET Standard library providing exclusive lock on file.

Using

Install the Xabe.FileLock NuGet package via nuget:

PM> Install-Package Xabe.FileLock

Creating file lock:

ILock fileLock = new FileLock(file);
fileLock.TryAcquire(TimeSpan.FromSeconds(15), true);

This will create lock file with extension ".lock" in the same directory. Example: "/tmp/data.txt" -> "/tmp/data.lock".

Last parameter is optional and defines if lock should be automatically refreshing before expired.

If file already has lock file, and it time haven't expired, method returns false.

Recommended using

ILock fileLock = new FileLock(file);
if(await fileLock.TryAcquire(TimeSpan.FromSeconds(15), true))
{
	using(fileLock)
	{
		// file operations here
	}
}

Lincence

Xabe.FileLock is licensed under MIT - see License for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published