/// <summary> /// 파일에 대한 <see cref="Lock"/>을 해제합니다. 중복된 Unlock 처리를 지시하면 예외가 발생합니다. /// </summary> /// <exception cref="IOException"/> public void Unlock() { FileStream fs = _filestream; if (fs == null || _state != FileHolderState.Locked) { throw new IOException("파일이 이미 닫혀 있습니다."); } _state = FileHolderState.Unlocking; fs.Dispose(); _filestream = null; _state = FileHolderState.Unlocked; }
/// <summary> /// <see cref="FileName"/>으로 지정된 경로 문자열에 해당하는 파일을 잠금 처리합니다. 중복된 Lock 처리를 지시하면 예외가 발생합니다. /// </summary> /// <exception cref="ArgumentException"/> /// <exception cref="ArgumentNullException"/> /// <exception cref="PathTooLongException"/> /// <exception cref="DirectoryNotFoundException"/> /// <exception cref="UnauthorizedAccessException"/> /// <exception cref="FileNotFoundException"/> /// <exception cref="NotSupportedException"/> /// <exception cref="IOException"/> public void Lock() { FileStream fs = _filestream; string fn = _filename; if (fs != null || _state != FileHolderState.Idle) { throw new IOException("파일이 이미 열려 있습니다."); } _state = FileHolderState.Locking; fs = File.OpenRead(fn); _filestream = fs; _state = FileHolderState.Locked; }