退出表单后,我收到ObjectDisposedException
。基本表单是我继承自Windows.Forms.Form
的自定义类,它适用于我的其他11个表单。
不幸的是,仅在我在datagrid中选择一行后才会出现此错误。
stacktrace:
at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)
at System.Windows.Forms.ScrollBar._GetInfo(AGL_SCROLLINFO_GRBIT grbit, AGL_SCROLLINFO& scrollinfo)
at System.Windows.Forms.ScrollBar.get_Value()
at System.Windows.Forms.GridRenderer._GetRectAt(Int32 irow, Int32 icol)
at System.Windows.Forms.GridRenderer._DrawCells(Graphics gx)
at System.Windows.Forms.GridRenderer._RenderCell(Graphics gxControl, Int32 irow, Int32 icol)
at System.Windows.Forms.GridRenderer._RenderCell(Int32 irow, Int32 icol)
at System.Windows.Forms.DataGrid._FocusChanged()
at System.Windows.Forms.DataGrid.OnLostFocus(EventArgs e)
at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.WL.Destroy(IntPtr hwnThis)
at System.Windows.Forms.Control.Dispose(Boolean disposing)
at System.Windows.Forms.DataGrid.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at SpaghettiCode.Interface_Wyd.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at SpaghettiCode.PZ_Wydania.PZ_Wydania_Closing(Object sender, CancelEventArgs e)
at System.Windows.Forms.Form.OnClosing(CancelEventArgs e)
at System.Windows.Forms.Form._FCanClose()
at System.Windows.Forms.Form._CloseModal()
at System.Windows.Forms.Form.Close()
at SpaghettiCode.ExtendedForm.set_CloseApp(Boolean value)
at SpaghettiCode.ExtendedForm.Exit_Click(Object sender, EventArgs e)
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)
at System.Windows.Forms.Form.ShowDialog()
at SpaghettiCode.Admin_Tools.init_tool()
at SpaghettiCode.Admin_Tools.Admin_Tools_KeyDown(Object sender, KeyEventArgs e)
at System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
at OpenNETCF.Windows.Forms.OwnerDrawnList.OnKeyDown(KeyEventArgs e)
at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)
at System.Windows.Forms.Form.ShowDialog()
at SpaghettiCode.Wybor.Alloption_menu_KeyDown(Object sender, KeyEventArgs e)
at System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.ListView.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)
at System.Windows.Forms.Form.ShowDialog()
at SpaghettiCode.Form1._result_of_verification_positive(String msg)
at SpaghettiCode.Form1.send_logpass()
at SpaghettiCode.Form1.Form1_KeyDown(Object sender, KeyEventArgs e)
at System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.ContainerControl.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at OpenNETCF.Windows.Forms.NativeMethods.DispatchMessage(MSG& lpMsg)
at OpenNETCF.Windows.Forms.Application2.Pump()
at OpenNETCF.Windows.Forms.Application2.RunMessageLoop(Boolean showForm)
at OpenNETCF.Windows.Forms.Application2.Run(Form mainForm, Boolean runAsSingletonApp, Boolean displayMainForm)
at OpenNETCF.Windows.Forms.Application2.Run(Form mainForm)
at SpaghettiCode.Program.Main()
我没有使用任何特殊的图纸,除了改变我已经确认没有区别的列大小和字体。
我的基本表单类继承自Windows.Forms,因此我将其处理为:
public class ExtendedForm : System.Windows.Forms.Form
protected override void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing)
{
if (mainTimer != null)
{
mainTimer.Enabled = false;
mainTimer.Tick -= mainTimer_Tick;
mainTimer.Dispose();
mainTimer = null;
isTimerDead = true;
}
if (panel1 != null)
{
panel1.Dispose();
mainmenu.Dispose();
Exit.Dispose();
MenuBack.Dispose();
panel1 = null;
mainmenu = null;
Exit = null;
MenuBack = null;
}
if (barcode != null)
{
barcode.Dispose();
barcode = null;
}
}
disposed = true;
base.Dispose(disposing);
}
虽然我的主界面是继承和处理的,但是这样:
class Interface_Wyd : ExtendedForm
protected override void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing)
{
// Free any other managed objects here.
this.Timer_work.Enabled = false;
this.Timer_work.Dispose();
this.List_Box_.Dispose();
//this helped me once with DisposedException in other form with datagrid. No effect here though.
this.DataGr_.UnSelect(this.DG_intf.CurrentCell.RowNumber);
this.DataTab_intf.Dispose();
this.DataGr_.Dispose();
this.LV_bott_intf.Dispose(); <--- signalizes an exception here but the problem is with DataGrid.
}
// Free any unmanaged objects here.
//
disposed = true;
base.Dispose(true);
}
~Interface_Wyd() { Dispose(false); }
答案 0 :(得分:1)
对于那些可能再次遇到同样错误的人: 在处理它们之前,不要忘记从主面板上移除控件。如果我没有选择数据网格中的任何单元格,我仍然想知道它为什么会起作用。显然,当我这样做的时候,windows在某个地方执行了绘图和存储句柄到datagrid,并试图在以后再用它不再存在的对象。