Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Cannot access disposed object (Read 1596 times)
pelion
Junior Member
**
Offline



Posts: 61
Joined: Nov 12th, 2006
Cannot access disposed object
Nov 11th, 2007 at 10:58pm
Print Post  
Hi Stoyo,

A tricky one here,

I have a main application form which calls another form to display a chart. The form with the chart on it is global to the scope of the form, but if a user closes the chart form, then tries to reopen it I have to reinstansiate it as below

Code
Select All
private void RefreshSolutionBuilderDialog()
        {
            if (dlgSolutionBuilder == null || dlgSolutionBuilder.IsDisposed)
            {
                dlgSolutionBuilder = new dlgSolutionBuilder(program, database); 



Now when I use the chart on the dialog I am likely to get the following error
Quote:
Cannot access a disposed object.
Object name: 'FlowChart'.


The stack trace is too long for this mesage, but it starts

Quote:
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.CreateGraphicsInternal()
at System.Windows.Forms.Control.CreateGraphics()
at MindFusion.Diagramming.WinForms.Box.xd1bdd0ee5924b59e()
at MindFusion.Diagramming.WinForms.Box..ctor(FlowChart parent)
at MindFusion.Diagramming.WinForms.FlowChart.CreateBox(Single x, Single y, Single width, Single height)
at


Any thoughts?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Cannot access disposed object
Reply #1 - Nov 12th, 2007 at 6:13am
Print Post  
Hi,

That looks like the problem discussed in this thread:
http://mindfusion.org/cgi/Forum/YaBB.pl?board=fcnet_brep;action=display;num=1187...

In short, make sure that all references to the closed forms, including event handlers raised from within the child forms but handled in the main form, or vice versa, are removed / detached. Otherwise, the disposed form might still raise some events or get some of its event handlers called. Disposing the form also disposes all child controls, including the flowchart. So when CreateBox tries to create a Graphics object, you get that exception.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
pelion
Junior Member
**
Offline



Posts: 61
Joined: Nov 12th, 2006
Re: Cannot access disposed object
Reply #2 - Nov 12th, 2007 at 7:33pm
Print Post  
I was working down that path, so I'll give it a bit of further work and see how it goes
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint