2012-02-16 297 views
2

我得到具有堆栈跟踪误差...System.ObjectDisposedException:无法访问已处理的对象 - 为什么发生?

System.ObjectDisposedException: Cannot access a disposed object. 
Object name: 'Button'. 
at System.Windows.Forms.Control.CreateHandle() 
at System.Windows.Forms.Control.get_Handle() 
at System.Windows.Forms.Control.PointToScreen(Point p) 
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
at System.Windows.Forms.Control.WndProc(Message& m) 
at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
at System.Windows.Forms.Button.WndProc(Message& m) 
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

产生这个错误代码是....

Friend Sub GoHome(ByVal sender As Form) 
    InTransit = True 
    sender.Close() 
    fMain.Show() 
End Sub 

它不给错误,当我刚刚切换的顺序在.show和.close方法

Friend Sub GoHome(ByVal sender As Form) 
    InTransit = True 
    fMain.Show() 
    sender.Close() 
End Sub 

能否请你告诉我,为什么在第一种情况下提示错误,为什么在第二种情况下它不?

+0

更多有趣的信息...。 我只在应用程序被虚拟化时发生(Citrix) 如果它运行在同一台计算机上,它就不会发生。 当代码包含消息框时,它不会给出错误。 此代码工作正常,没有任何错误... 朋友小组GOHOME(BYVAL发件人为表) 途=真 MSGBOX(“任何消息”) sender.Close() fMain.Show() 完子 – rai 2012-02-16 15:40:20

回答

0

senderfMain在这种情况下是同一个对象吗?

如果是这样......当您拨打sender.Close时,您实际上呼叫fMain.Close,而Close方法将在幕后处理该对象。如果您随后致电fMain.Show,那么您将其称为您刚放置的对象,因此出现错误。

,或者...

也许senderfMain子控件的一个?

您打电话给sender.Close,配置子控件。然后您拨打fMain.Show试图做东西与属于fMain的子控件。当它试图用刚刚处理的子控件执行特定操作时会发生该错误。

相关问题