C#:异常-参数无效-表单处理方法 [英] C#: Exception - Parameter is not valid - Form Dispose method

查看:190
本文介绍了C#:异常-参数无效-表单处理方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理表单对象时,从另一个例外处理抛出类似参数无效

While disposing the object of a form from the other an exception is throwing likeParameter is not valid

访问第二个表单的代码

        Assembly X = Assembly.LoadFile(Application.StartupPath + "\\Test.dll");
        Form frminv = (Form)X.CreateInstance("Test.Form1");
        frminv.Dispose();

这里是表单处理方法(来自Designer.cs)

Here is the form disposal method( from Designer.cs)

protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);// exception is thrown from here
    }

这是堆栈跟踪

     at System.Drawing.Image.get_FrameDimensionsList()
 at System.Drawing.ImageAnimator.CanAnimate(Image image)
 at System.Drawing.ImageAnimator.ImageInfo..ctor(Image image)
 at System.Drawing.ImageAnimator.Animate(Image image, EventHandler onFrameChangedHandler)
 at System.Windows.Forms.PictureBox.Animate(Boolean animate)
 at System.Windows.Forms.PictureBox.Animate()
 at System.Windows.Forms.PictureBox.OnVisibleChanged(EventArgs e)
 at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
 at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
 at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
 at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
 at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
 at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
 at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
 at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
 at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
 at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
 at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
 at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
 at System.Windows.Forms.Control.WmShowWindow(Message& m)
 at System.Windows.Forms.Control.WndProc(Message& m)
 at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
 at System.Windows.Forms.ContainerControl.WndProc(Message& m)
 at System.Windows.Forms.Form.WmShowWindow(Message& m)
 at System.Windows.Forms.Form.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 at System.Windows.Forms.UnsafeNativeMethods.IntDestroyWindow(HandleRef hWnd)
 at System.Windows.Forms.UnsafeNativeMethods.DestroyWindow(HandleRef hWnd)
 at System.Windows.Forms.NativeWindow.DestroyHandle()
 at System.Windows.Forms.Control.DestroyHandle()
 at System.Windows.Forms.Control.Dispose(Boolean disposing)
 at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
 at System.Windows.Forms.Form.Dispose(Boolean disposing)
 at ICFTWaveForm.WaveForm.Dispose(Boolean disposing)
 at System.ComponentModel.Component.Dispose()
 at System.Windows.Forms.Control.Dispose(Boolean disposing)
 at System.ComponentModel.Component.Dispose()
 at System.Windows.Forms.Control.Dispose(Boolean disposing)
 at System.ComponentModel.Component.Dispose()
 at System.Windows.Forms.Control.Dispose(Boolean disposing)
 at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
 at System.Windows.Forms.Form.Dispose(Boolean disposing)
 at XXXX.frmMain.Dispose(Boolean disposing) in E:\XXXX\XXXX\frmMain.Designer.cs:line 20
 at System.ComponentModel.Component.Dispose()
 at XXXX.TestComponents.OpenComponentForTestting(stComponents TestComponent, stTestStepDetails Test, enExecutionModeTypes Mode, Boolean IsVisibleMode, Int32 nStepIndex, Int32 nTotalSteps) in E:\My Projects\XXXXXXXX\frmMDIContainer.cs:line 3145

会出现什么问题。
请帮助我。

what will be the problem. Please help me.

推荐答案

我必须查看代码以确保,但也许我可以帮助您查看正确的位置...

I'd have to look at the code to be sure, but perhaps I can help you look in the right places...

堆栈跟踪表明在Dispose序列中发生了PictureBox中动画的重绘。那么为什么图片框在应该死了的情况下为什么要尝试这样做呢?

The stack trace indicates that a redraw of an animation in a pictureBox is occurring during the Dispose sequence. So why is the picturebox trying to do this when it's supposed to be dead?

在这种情况下,您可能需要执行以下操作:Close()处置它,彻底关闭所有内容(例如,在调用base.Dispose()之前在图片框中禁用动画),或者可能在您的类中创建了一些其他资源,需要对其进行处置,然后才能安全地调用base.Dispose。另外,您可能已经处置了仍然需要的东西(例如pictureBox正在尝试访问的Image)-检查将实际处置哪些处置组件。

In these sort of cases you may need to do something like: Close() your window before disposing it, shut things down cleanly (e.g. disable animation in the picturebox before calling base.Dispose()), or there may be other resources that are created in your class and need to be disposed before you can safely call base.Dispose. Alternatively, you may have already Disposed of something that is still needed (e.g. the Image that the pictureBox is trying to access) - check what disposing "components" will actually dispose of.

这篇关于C#:异常-参数无效-表单处理方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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