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

前端 未结 3 1002
臣服心动
臣服心动 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

    It looks like the two suggestions from this MSDN forum posting both involve trying to open the file.

    The first one is similar to what you are doing now, and the second involves using a Windows API function (CreateFile) and checking for a invalid handle signifying the file is in use. In both cases they are relying on an error condition to determine if the file is open or not. In short, in my opinion the method you are using is correct since there is not a System.IO.File.IsOpen property.

提交回复
热议问题