简体   繁体   English

vb.net使用的查杀进程

[英]killing process used by vb.net

I need some help with my program. 我的程序需要一些帮助。 I want to rewrite the data on my .txt file but an error occurs: 我想重写.txt文件上的数据,但发生错误:

The process cannot access the file 'C:\\Users\\AARVIII\\Documents\\Visual Studio 2010\\Projects\\PROJECT\\WindowsApplication3\\bin\\Debug\\ORDERS\\aa.txt' because it is being used by another process. 该进程无法访问文件'C:\\ Users \\ AARVIII \\ Documents \\ Visual Studio 2010 \\ Projects \\ PROJECT \\ WindowsApplication3 \\ bin \\ Debug \\ ORDERS \\ aa.txt',因为该文件正在被另一个进程使用。

Here is the code: 这是代码:

Sub WRITEDATA()

    Dim write As New System.IO.StreamWriter("ORDERS\" & TBFNAME.Text + "" + TBLNAME.Text & ".txt", False)
    write.WriteLine(TBFNAME.Text)
    write.WriteLine(TBLNAME.Text)
    write.WriteLine(TBEADD.Text)
    write.WriteLine(TBEADD2.Text)
    write.WriteLine(TBADDRESS.Text)
    write.WriteLine(TBCONTACT.Text)
    write.close()

End Sub

I used a StreamReader to get the data which had already been put in that text file. 我使用StreamReader来获取已经放在该文本文件中的数据。 Please help me figure out how to kill that process so that I can rewrite my data. 请帮助我弄清楚如何终止该进程,以便我可以重写数据。

It is very possible that your app (on another thread?) is the culprit. 您的应用程序(在另一个线程上?)很可能是罪魁祸首。 First, to make sure you release the resource, make sure to wrap your code in a using block: 首先,要确保释放资源,请确保将代码包装在using块中:

  Using Dim write As New System.IO.StreamWriter("ORDERS\" & TBFNAME.Text + "" + TBLNAME.Text & ".txt", False)
        write.WriteLine(TBFNAME.Text)
        write.WriteLine(TBLNAME.Text)
        write.WriteLine(TBEADD.Text)
        write.WriteLine(TBEADD2.Text)
        write.WriteLine(TBADDRESS.Text)
        write.WriteLine(TBCONTACT.Text)
  End Using

Additionally, you may want to see this thread: .NET Asynchronous stream read/write 此外,您可能希望看到以下线程: .NET异步流读/写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM