How to suppress / catch a System.ObjectDisposedException?

I have an application that sporadically throws this exception:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: "Panel". 
   bei System.Windows.Forms.Control.CreateHandle() 
   bei System.Windows.Forms.Control.get_Handle() 
   bei System.Windows.Forms.ContainerControl.FocusActiveControlInternal() 
   bei System.Windows.Forms.Form.set_Active(Boolean value) 
   bei System.Windows.Forms.Form.WmActivate(Message& m) 
   bei System.Windows.Forms.Form.WndProc(Message& m) 
   bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
   bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
   bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Is there a way to suppress this exception perfectly without touching the code? I am thinking of some kind of registry magic or esoteric .NET configurations.

In addition, I, of course, am also interested in ways to catch this exception. I don't seem to have a hook to catch this exception ... And, of course, this is not reproducible ...

+3
source share
3 answers

About catching an exception; I assume that in this application there is no global exception handling?

In the program Program.cs:

static void Main()
{
    Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

    Application.Run(new MainForm());
}

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    // Handle exception
    Application.Exit();
}

static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
    // Handle exception
    Application.Exit();
}

. , . , ObjectDisposedException .

+3

" , , ? , ?"

, , .

, . , , . .

, , " ", , , , , .

, , , , , .

+6

- . ! .

, . , : 1) , . 2) .

EDIT. To help you fix this problem, you can configure ADPlus to create dump files for this particular exception. This may give you some idea of ​​why this is happening. John Robbins published a Bugslayer article on how to do this. See http://msdn.microsoft.com/en-us/magazine/cc163530.aspx .

+5
source

Source: https://habr.com/ru/post/1720866/


All Articles