Hi This two lines of code have always worked fine
System.Windows.Forms.Form ModificaPrenotazione = new
ModificaPrenotazione(id_preno);
ModificaPrenotazione.Show();
But, after some changes to the logics in the ModificaPrenotazione Form
(Changes like new button, new buttons event, etc..) , the method show()
throws this execption "ObjectDisposedException was unhandled" Cannot
access a disposed object
What have I done to my code to make it doesn't work?? why was it
working fine and now it doesn't work?
How can I resolve this problem??
Exception details:
System.ObjectDisposedException was unhandled
Message="Cannot access a disposed object.\r\nObject name:
'ModificaPrenotazione'."
Source="System.Windows.Forms"
ObjectName="ModificaPrenotazione"
StackTrace:
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at
AnyHotel.ResocontoStanzaUserControl.b_MouseClick_VisualizzaPrenotazione(Object
sender, MouseEventArgs e) in C:\Documents and
Settings\Lavoro\Documenti\Visual Studio
2005\Projects\AnyHotel\AnyHotel\ResocontoStanzaUserControl.cs:line 233
at System.Windows.Forms.Control.OnMouseClick(MouseEventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at AnyHotel.Program.Main() in C:\Documents and
Settings\Lavoro\Documenti\Visual Studio
2005\Projects\AnyHotel\AnyHotel\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Bob Powell [MVP] - 07 Jul 2006 18:52 GMT
You should be doing something like:
ModificaPrenotazione myform = new
ModificaPrenotazione(id_preno);
myform.Show();
If it still happens, you'll need to see what you did to break the form. Did
you edit the InitializeComponent by hand?? thats the bit where it says "DO
NOT EDIT THIS BY HAND" :-)

Signature
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
> Hi This two lines of code have always worked fine
>
[quoted text clipped - 68 lines]
> executionContext, ContextCallback callback, Object state)
> at System.Threading.ThreadHelper.ThreadStart()