FileStream.Lock : FileStream « System.IO « VB.Net by API






FileStream.Lock

  

Imports System.IO

Module Module1

    Sub Main()
        Dim FileSt As FileStream = New FileStream("test.dat", FileMode.Create, FileAccess.Write, FileShare.Write)

        Try
            FileSt.Lock(0, 100)
            Console.WriteLine("Locked")
        Catch Ex As Exception
            Console.WriteLine(Ex.Message)
        End Try

        Try
            FileSt.Unlock(0, 100)
            Console.WriteLine("Unlocked")
        Catch Ex As Exception
            Console.WriteLine(Ex.Message)
        End Try

        Dim Values As Byte()
        Values = New Byte() {1, 2, 3, 4, 5}

        Try
            FileSt.Seek(0, SeekOrigin.Begin)
            FileSt.Write(Values, 0, 5)
            Console.WriteLine("Successfully updated file")
        Catch Ex As Exception
            Console.WriteLine(Ex.Message)
        End Try

    End Sub

End Module

   
    
  








Related examples in the same category

1.New FileStream(String fileName, FileMode fm)
2.FileStream.Length
3.FileStream.Seek
4.FileStream.SetLength
5.FileStream.Unlock
6.FileSystem.GetFileInfo