调试时VB.net中的问题 [英] Problems in VB.net when debugging

查看:87
本文介绍了调试时VB.net中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我正在测试一种表单,该表单中有一个streamwriter概念可将数据写到文本文件中.我没有问题,除了调试时,如果我在测试4到5次以上时填写表格,它将停止并以黄色突出显示整个Streamwriter代码行,对我说:

IOExeption未处理
该进程无法访问文件"C:\ Test.txt",因为它正在被另一个进程使用.

我不知道为什么在调试时填写表格的5倍以上时会这样说.

Well, I''m testing a form where there is a streamwriter concept to write data in a text file. I don''t have problem with it, except when debugging, if I fill the form when testing more than 4 or 5 times, it stops and highlighted in yellow colour the entire line of the streamwriter code saying to me:

IOExeption was unhandled
The process cannot access the file ''C:\Test.txt'' because it is being used by another process.

I don''t know why it is saying this when filling more than 5 times the form when debugging. The file is not opened anywhere, it is just in the Local Drive C.

推荐答案

无法打开文件,因为它仍处于锁定状态,可能是由于先前使用的流而导致无法打开作家.您的页面尝试再次打开该文件,但是之前被垃圾回收ansd删除的StreamWriter仍然对该文件保持锁定.

您应该执行以下操作:

1)捕获并处理此函数中的异常.访问文件时总是会发生无法预见的错误,并且您不希望仅此原因而导致网站崩溃.

2)无论发生什么情况,在关闭StreamWriter的位置添加一个 finally 块.之后,您必须调用其Dispose()方法来释放任何资源(和文件锁),而无需等待垃圾回收.
The file cannot be opened because it is still locked, probably by your previously used stream writer. Your page tries to open the file again, but the StreamWriter which has been used before has not yet been deleted by the garbage collection ansd still holds a lock on the file.

You should do the following things:

1) Catch and handle exceptions in this function. Unforseeable errors can always happen when accessing files and you do not want your website to crash just because of that.

2) Add a finally block where you close the StreamWriter, no matter what has happened. After that you must call its Dispose() method to release any resources (and file locks) without waiting for the garbage collection.


错误消息告诉您正在发生什么,该文件是锁定.我会确保你


1.写入文件时没有任何错误
2.写入文件后释放文件.
The error message is telling you what is happening, the file is locked. I would make sure that you


1. Dont have any errors while writing to the file
2. Releasing the file after writing to it.


一个原因可能是:您已经使用StreamWriter打开了文件,并且在调用StreamWriter.Close()之前退出了应用程序.

确保退出应用程序之前关闭StreamWriter.
希望这会有所帮助.
一切顺利.
One reason could be : You have opened the file using StreamWriter and before calling StreamWriter.Close() you have exited the application.

Make sure you close the StreamWriter before exiting the application.
Hope this helps.
All the best.


这篇关于调试时VB.net中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆