Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

Cannot access a disposed object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joiko - 07 Jul 2006 12:54 GMT
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()

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.