2012-02-16 73 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的子控件。當它試圖用剛剛處理的子控件執行特定操作時會發生該錯誤。

相關問題