Class InstanceLockFile
- Namespace
- VpnHood.AppLib.App
- Assembly
- VpnHood.AppLib.App.dll
Provides an app's single-instance lock as a file, in a folder its host names: one only root may write, as the Linux service's, or one the person owns.
public static class InstanceLockFile
- Inheritance
-
InstanceLockFile
- Inherited Members
Remarks
The file is held open with no sharing, which .NET makes an exclusive flock on Linux, and the system lets it
go with the process, so a crash leaves no stale lock. On Linux a new lock file is readable and writable by its
owner only, as a lock anyone may read is one anyone may hold; a file that is there keeps its permissions.
Fields
FileName
The lock file's name in its folder.
public const string FileName = "instance.lock"
Field Value
Methods
IsHeld(IOException)
Returns a value indicating whether an exception from opening a file says another open holds it: a sharing or
lock violation on Windows, flock's EWOULDBLOCK on Linux.
public static bool IsHeld(IOException ex)
Parameters
exIOExceptionThe exception from the open.
Returns
Take(string, string)
Takes the lock, making its folder where there is none.
public static FileStream Take(string folderPath, string appId)
Parameters
folderPathstringThe folder of the lock file.
appIdstringThe app's ID, which the exception names.
Returns
- FileStream
The open lock file, which holds the lock until it is disposed or the process ends.
Exceptions
- AnotherInstanceIsRunningException
Another process holds the lock.
- IOException
The file could not be opened for another reason.
- UnauthorizedAccessException
The process may not write the folder or the file.