VB.NET Checking if a File is Open before proceeding with a Read/Write?

前端 未结 3 1001
臣服心动
臣服心动 2020-12-01 19:31

Is there a method to verify that a file is open? The only thing I can think of is the Try/Catch to see if i can catch the file-open exception but I figured tha

3条回答
  •  囚心锁ツ
    2020-12-01 20:01

    There is really no point using a 'is file in use check' function since you will still need to have try catch to handle the case that the file fails to open. The file open can fail for many more reasons than it just being already open.

    Also using a function to do a check is no guarantee of success. The 'is file in use check' might return false only for the file open to fail with a file already open error, because in time between the check and trying to open the file it was opened by someone else.

提交回复
热议问题