我正在IO.Directory.GetFiles用来搜索文件夹中的文件.搜索完成后,在我的应用程序关闭之前,我无法使用此文件夹中的文件.我没有Dispose在DirectoryInfo课堂上找到任何功能,所以我的问题是:如何释放或解锁这些文件?
我的代码:
Dim list = IO.Directory.GetFiles(folder, "*.*", IO.SearchOption.AllDirectories)
Run Code Online (Sandbox Code Playgroud)
编辑:
我已经非常仔细地检查了我的代码(我无法在另一个项目中重现我的问题),事实证明这个函数是锁定文件:
Public Function ComputeFileHash(ByVal filePath As String)
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim f As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
f = New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(f)
f.Close()
f.Dispose()
Dim hash As Byte() = md5.Hash
Dim buff As Text.StringBuilder = New Text.StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format("{0:X2}", hashByte))
Next
Dim md5string As String …Run Code Online (Sandbox Code Playgroud)