2012-02-16 4 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의 보낸 사람) InTransit = 진정한 있는 MsgBox ("모든 메시지") sender.Close() fMain.Show() 최종 하위 – rai

답변

0

senderfMain이 경우 동일한 개체입니까?

sender.Close으로 전화하면 효과적으로 fMain.Close으로 전화를 걸고 Close 메서드는 그 개체를 배경으로 처리합니다. 나중에 fMain.Show을 호출하면 방금 처리 한 객체에서 호출되므로 오류가 발생합니다.

또는 대안 ...

어쩌면 senderfMain에 자식 컨트롤 중 하나입니다?

sender.Close으로 전화하여 하위 컨트롤을 삭제합니다. 그런 다음 fMain.Show을 호출하면 무언가가이고 자식 컨트롤은 fMain에 속합니다. 방금 처분 한 자식 컨트롤을 사용하여 특정 작업을 수행하려고하면 오류가 발생합니다.

관련 문제