Snickel65

In the load event for my main form in my C# Windows Forms app, there is a case where I need to call this.Close(); When this happens, I get the ObjectDisposedException thrown.

My main routine in program.cs looks like this:

using (Form1 frm = new Form1())
{
Application.Run(frm);
}

Any help at all is appreciated!!



Re: .NET Base Class Library ObjectDisposedException

Peter Ritchie

It would be more helpful to see the contents of your Load event handler. Do you know what object the ObjectDisposedException is being raised upon Or, is it thrown when you call Form.Close




Re: .NET Base Class Library ObjectDisposedException

nobugz

Your "using" statement is unnecessary, Form.Close() already calls Dispose(). That's however probably not the source of your exception. Be sure to not touch any of the form's properties and controls after you call Close(). If necessary, set a breakpoint on the Dispose method in the Design.cs file and single-step to find out what your code is doing after disposing the form.





Re: .NET Base Class Library ObjectDisposedException

Snickel65

It's thrown when I call "this.Close();" from SaveAndExit(); 

Here is my load event handler:

{
Caesar
.Config.FRPProperties.DatafileChanged += new fileChangedDelegate(FRPDatafileChanged);
Caesar.Config.DatabaseDefinitions.UnitFileChanged += new fileChangedDelegate(UnitFileChanged);
InitializeValidItems();
this.Text = String.Format("{0} v{1:f2}", this.Text, 5.10);
categoryPane = DockingPaneManager.CreatePane(1, categoryTreeForm.Size.Width, 250,
XtremeDockingPane.
DockingDirection.DockLeftOf);
categoryPane.Options =
PaneOptions.PaneNoCloseable;
categoryPane.Title =
"Categories";
categoryTreeForm.treeView1.AfterSelect +=
new TreeViewEventHandler(treeView1_AfterSelect);|
CommandBars.EnableOffice2007Frame(
true);
CommandBars.DeleteAll();
InitializeProtection();
helpProvider1.HelpNamespace =
String.Format(@"{0}c2_docu\c2tr.chm", Coade.ProgramDirectory);

if (this.executionFlag == 1)
    this.TopMost = true;
else if (this.executionFlag == 2)
    SaveAndExit();
}





Re: .NET Base Class Library ObjectDisposedException

AndrewVos

This is a bug in .net2 I believe.




Re: .NET Base Class Library ObjectDisposedException

Peter Ritchie

The only thing I could find similar to what is described is : https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx FeedbackID=148259