/// <summary> /// Checks if the lock file exists, and does whatever you ask in the argument. /// </summary> /// <param name="LockOperation">The operation to perform.</param> /// <returns>true if the lock file exists, false otherwise.</returns> /// <exception cref="IOException">thrown if the lock file could not be deleted/created</exception> public bool IsLocked(LockOperations LockOperation) { if (File.Exists(this.LockFileFullPath)) { if (LockOperation == LockOperations.RemoveLock) try { File.Delete(this.LockFileFullPath); } catch (Exception ex) { throw new IOException("Lock File could not be deleted. Try deleting it manually: " + this.LockFileFullPath ,ex); } return true; } else { // Lock file doesn't exist if (LockOperation == LockOperations.CreateLock) { try { using (StreamWriter writer = File.CreateText( this.LockFileFullPath )){ writer.Write(DateTime.Now.ToString() + " " + Environment.UserName); } } catch (Exception ex) { throw new IOException("Lock File could not be created.",ex); } } return false; } }
internal static extern int FLock(IntPtr fd, LockOperations operation);
internal static extern int FLock(SafeFileHandle fd, LockOperations operation);
internal static extern int flock(int fd, LockOperations operation);
internal static partial int FLock(IntPtr fd, LockOperations operation);
internal static partial int FLock(SafeFileHandle fd, LockOperations operation);
internal static extern int FLock(int fd, LockOperations operation);