Skip to content

Instantly share code, notes, and snippets.

@fredgdaley2
Created June 29, 2016 14:27
Show Gist options
  • Save fredgdaley2/ce6424a37fe84a6a869438709fa5613c to your computer and use it in GitHub Desktop.
Save fredgdaley2/ce6424a37fe84a6a869438709fa5613c to your computer and use it in GitHub Desktop.
Wait for a file to be accessible if not wait 10 seconds and try again.
Public Sub WaitForFileToBeAccessible(ByVal fileWaitingOn As String)
Try
Using fs As FileStream = New FileStream(fileWaitingOn, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 100)
fs.ReadByte()
End Using
Catch ex As Exception
System.Threading.Thread.Sleep(10000)
WaitForFileToBeAccessible(fileWaitingOn)
End Try
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment