如何知道从 SQLite 创建的 csv 已关闭以便我可以从中读取?

How do know the csv created from SQLite is closed so I can read from it?

在vb.net,我有我的程序运行sqlite3.exe。 Sqlite3 运行s以下命令,存储在文本文件中:

.open prod.db
.mode csv
.output output.csv
SELECT STATEMENT
.output stdout
.exit

一旦创建了 output.csv,然后我 运行 一个 Streamreader 来查看结果是什么,我得到以下错误:

The process cannot access the file 'output.csv' because it is being used by another process.

但是,我知道它不会被锁定太久,因为我可以在创建后转到 csv 并手动打开它。

我会编写代码来检查进程何时完成,但我不确定进程是什么 运行 检查这个(我已经检查 SQLite3.exe 是否关闭)。换句话说,我怎么知道我的 csv 可以免费打开 Streamreader?

使用 droque 的 link"

VB.Net 3.5 Check if file is in use

我能够将其与我自己的一些代码结合起来解决问题:

While FileInUse("output.csv") And j < 100
        System.Threading.Thread.Sleep(100)
            j += 1
End While
'Timeout after ~10 seconds
If j = 100 Then
        MessageBox.Show("CSV timeout.  Exiting now.")
        Exit Sub
End If

此处定义了 FileInUse:

Public Function FileInUse(ByVal sFile As String) As Boolean
        Dim thisFileInUse As Boolean = False
        If System.IO.File.Exists(sFile) Then
            Try
                Using f As New IO.FileStream(sFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
                    ' thisFileInUse = False
                End Using
            Catch
                thisFileInUse = True
            End Try
        End If
        Return thisFileInUse
    End Function