C#:ObjectDisposeException 未被用户代码处理
我正在开发一个秘密项目,基本上它的作用是使用网络浏览器进入页面,填写表格,然后单击提交。
昨天一切正常,但今天每次启动向网站上的表单填写数据的代码时,我的界面都会滞后。
在 C# IDE 中,这是我收到的错误:
C#:ObjectDisposeException 未由用户代码处理
......当我查看它的详细信息时,我得到:
名称“$exception”在当前上下文中不存在
有人知道我必须做什么吗?我必须扔掉一些东西还是……?
I have a secret project I am working on and basically what it does is go to a page using the web browser fills out the form then clicks submit.
Yesterday everything was working OK but today my interface keeps lagging everytime the code to fill out data to forms on the site starts.
In the C# IDE this is the error I am getting:
C#: ObjectDisposedException was unhandled by user code
...and when I view the details of it I get:
The name '$exception' does not exist in the current context
Anybody have any idea of what I have to do? Do I have to dispose something or...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设它
是类型
,那么该错误仅仅意味着您在调用其余代码之前已经释放了 webBrowser1 对象。因此,解决方法就是确保在适当的时间处理该对象。
在 using 块内声明您的 webBrowser1 对象将使范围更加明确,例如
将有助于确保您适当地处理 WebBrowser 对象(因为它是资源密集型的)并且您仅在它处于活动状态时才使用它(因为它是只能在 using 块内访问)。
using 块还有助于确保即使在发生异常时也能正确处理。
Assuming that
is of type
then the error simply means that you already disposed the webBrowser1 object, prior to calling the rest of your code. So the fix is to simply make sure you dispose of the object at the appropriate time.
Declaring your webBrowser1 object inside of a using block will make the scope more explicit, e.g.
will help ensure that you both dispose of the WebBrowser object appropriately (since it is resource intensive) and that you only use it while it is active (since it is only accessible within the using block).
The using block also helps ensure proper disposal even when an exception occurs.