“无法访问已处置的对象” [英] "Cannot access a disposed object"

查看:147
本文介绍了“无法访问已处置的对象”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



任何人都可以告诉我为什么当我从1个表单迁移到另一个表单而没有关闭之前的时候我会收到无法访问已处理的对象错误形成。确切地说,我使用Windows窗体作为模态窗体,并且当我处于第一种形式时我已经启动了计时器,当我切换到第二种形式时,我正在停止计时器。此外,我使用委托来处理来自库的数据,并且可以从两个表单访问此库。因此,当我尝试打开第二个表单时,我在第二个表单中的委托事件中收到此错误。那么如何处理这种类型的错误呢?我得到的错误是无法访问已处置的对象。 对象名称:''Form2''。



那么有人能告诉我如何在不影响任何东西的情况下安全地在表格之间切换......?

Hi everyone,

Can anybody tell me why i get "Cannot access a disposed object" error when i am migrating from 1 form to another without closing the previous form. To be precise i am using windows form as modal forms, and i have started the timer when i am in the 1st form & when i switch to 2nd form i am stopping the timer. Also i have used delegates to process data from a library & this library is accessed from both the forms. So i get this error in the delegate event in the 2nd form when trying to open 2nd form. So how to handle this type of error? The error what i get is "Cannot access a disposed object." "Object name: ''Form2''".

So can anybody tell me how to safely switch between forms without affecting any of the stuffs like those...?

推荐答案

从评论中可以清楚地看到表格已处理。

From the comments it is clear that the Form is Disposed.
Add a breakpoint to the
protected override void Dispose(bool disposing)

表单的方法并检查导致处理表单的调用堆栈。

method of your form and check the call stack who caused the disposal of the Form.


这篇关于“无法访问已处置的对象”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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