Vb.net 停止使用文件

Vb.net 停止使用文件,vb.net,Vb.net,首先,我通过按标签创建了一个文件,然后我希望能够在不重新启动应用程序的情况下删除它,因为它正在使用中 代码是 Dim UniWinDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "UniWin Activator Data") Dim MsgIODat = Path.Combine(UniWinDataPath, "MessageIO.dat") If File.

首先,我通过按标签创建了一个文件,然后我希望能够在不重新启动应用程序的情况下删除它,因为它正在使用中

代码是

Dim UniWinDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "UniWin Activator Data")
Dim MsgIODat = Path.Combine(UniWinDataPath, "MessageIO.dat")
If File.Exists(MsgIODat) Then
    'ERROR HERE
    File.Delete(MsgIODat)
    '''''''''''''''''''''
    Dim clrdata = MessageBox.Show("Data Cleared.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf (Not (File.Exists(MsgIODat))) Then
    Dim nodata = MessageBox.Show("There is no data to clear.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
错误:进程无法访问文件“路径”,因为其他进程正在使用该文件

我搜索过,没有发现有人用vb.net语言谈论这个问题

有没有办法让我的应用程序停止使用它来删除文件?

您需要处理file.Create方法返回的FileStream。 创建文件时

File.Create("file").Dispose()

共享生成文件的代码。您几乎肯定需要在生成文件的流上使用Dispose方法,或者直接使用,或者使用using block.ill复制并粘贴确切的代码。。。see thread againI是指写入文件的代码-标签事件处理程序,而不是获取文件名的代码。@Wai代码是file.createpath