public Lock ( long position, long length ) : void | ||
position | long | |
length | long | |
return | void |
using System.IO; var file = new FileStream("example.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); file.Lock(0, file.Length); Console.WriteLine("File locked successfully");
using System.IO; var file = new FileStream("example.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); file.Lock(0, file.Length); Console.WriteLine("File locked successfully"); // code to manipulate the locked file file.Unlock(0, file.Length); Console.WriteLine("File unlocked successfully");This code example shows how to unlock a file by using the Unlock method. The code first locks the file as in Example 1, then performs some operations on the locked file, and finally unlocks the file using the Unlock method. The System.IO namespace is part of the standard .NET Framework library and does not require any additional packages or libraries.