Colleagues,
Say, you need to read from a file. You have the code similar to this:
Sure thing, the line loStreamReader = New StreamReader(tcFullPath2File) will throw exception if the file is open by another process.
Sure thing, you'd want to prevent this from happening by checking if the file is not in use, right?
Besides the obvious solution, e.g. make a lil' function that does this check with Try-Catch construct and returns True if an exception's caught - here comes the question:
Is there in the VB and/or .NET some built-in/native function that checks if a file is in use?
(I honestly tried to find it myself in the VS 2019 Reference "book" - and couldn't find anything :-( )
Please advise.
Regards,
Ilya
Say, you need to read from a file. You have the code similar to this:
Code:
Dim loStreamReader As StreamReader
Try
loStreamReader = New StreamReader(tcFullPath2File)
lsFileContents = loStreamReader.ReadToEnd()
Catch loErr As Exception
llGoOn = False
lsErrMsg = "Failure reading text from file " & tcFullPath2File & "!" & vbCrLf & Read_Exception(loErr) & vbCrLf & _
"Please exit this program and report this problem to the Developer."
MsgBox(lsErrMsg, vbCritical, lsMsgHdr)
lcRet = lsErrMsg
Finally
If llGoOn Then loStreamReader.Close()
End Try
Sure thing, you'd want to prevent this from happening by checking if the file is not in use, right?
Besides the obvious solution, e.g. make a lil' function that does this check with Try-Catch construct and returns True if an exception's caught - here comes the question:
Is there in the VB and/or .NET some built-in/native function that checks if a file is in use?
(I honestly tried to find it myself in the VS 2019 Reference "book" - and couldn't find anything :-( )
Please advise.
Regards,
Ilya