Xabe.FileLock.WithTimeout 2.1.0

Cross-platform library providing exclusive lock on file, with timeout functionality. Forked from: https://xabe.net/product/xabe_filelock/

There is a newer version of this package available.
See the version list below for details.
Install-Package Xabe.FileLock.WithTimeout -Version 2.1.0
dotnet add package Xabe.FileLock.WithTimeout --version 2.1.0
<PackageReference Include="Xabe.FileLock.WithTimeout" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xabe.FileLock.WithTimeout --version 2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Xabe.FileLock.WithTimeout

.NET Standard library providing exclusive lock on file. Additional functionality to acquire this lock with a timeout. Forked from: Xabe.Filelock

Using

Install the Xabe.FileLock.WithTimeout NuGet package via nuget:

PM> Install-Package Xabe.FileLock.WithTimeout

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
	}
}

Timeout functionality

Similarly to the code above we can await the FileLock until timeout. Note that refreshing the lock could complicate things:

ILockWithTimeout fileLock = new FileLockWithTimeout(file);
if (await fileLock.TryAcquireOrTimeout(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(30))
{
    using(fileLock)
    {
        // file operations here
    }
}
else
{
    // things to do if timeout happens
}

License

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

Xabe.FileLock.WithTimeout

.NET Standard library providing exclusive lock on file. Additional functionality to acquire this lock with a timeout. Forked from: Xabe.Filelock

Using

Install the Xabe.FileLock.WithTimeout NuGet package via nuget:

PM> Install-Package Xabe.FileLock.WithTimeout

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
	}
}

Timeout functionality

Similarly to the code above we can await the FileLock until timeout. Note that refreshing the lock could complicate things:

ILockWithTimeout fileLock = new FileLockWithTimeout(file);
if (await fileLock.TryAcquireOrTimeout(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(30))
{
    using(fileLock)
    {
        // file operations here
    }
}
else
{
    // things to do if timeout happens
}

License

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

  • .NETCoreApp 2.0

    • No dependencies.
  • .NETFramework 4.6

    • No dependencies.
  • .NETStandard 1.3

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.1.3 106 1/29/2019
2.1.2 101 1/24/2019
2.1.1 131 1/15/2019
2.1.0 132 1/15/2019
2.0.0 155 1/14/2019