473,781 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# error: cannot access disposed object

7 New Member
Hello All of u

Plz help me regarding some problem related c#.net

I have two forms form1 and form2

at the load of form1 i call another form2
Expand|Select|Wrap|Line Numbers
  1. form1_load()
  2. {
  3.  if(some condition)
  4.  {
  5.    form2 f2=new form2();
  6.    f2.show();
  7.    this.close();
  8.  }
  9. }
  10.  
when i close this form message show
"cannot access disposed object of form1"

and if close at the load of form2 then it is not close the form1.

plz any one help me
Jun 26 '07 #1
2 4574
Frinavale
9,735 Recognized Expert Moderator Expert
Hello All of u

Plz help me regarding some problem related c#.net

I have two forms form1 and form2

at the load of form1 i call another form2
Expand|Select|Wrap|Line Numbers
  1. form1_load()
  2. {
  3.  if(some condition)
  4.  {
  5.    form2 f2=new form2();
  6.    f2.show();
  7.    this.close();
  8.  }
  9. }
  10.  
when i close this form message show
"cannot access disposed object of form1"

and if close at the load of form2 then it is not close the form1.

plz any one help me
Hi karu,
Welcome to theScripts. I hope you like it here.

I have changed the title of your thread so that it better reflects the problem you are facing. Please provide a better description of the problem in the title in the future. Please review the Posting Guidelines for general rules we follow here on theScript.

As for your question: the line "this.close ();" will Dispose of your window (releases its resources and lets the garbage collector clean up)

You need to change the line to "this.hide( );" (or the equivalent...I' m not good with C#). Once you close something (or dispose of it) you cannot refer to it any longer.

Cheers!

-Frinny
Jun 26 '07 #2
TRScheel
638 Recognized Expert Contributor
If you want an child object to persist after you close the form, declare it as static. Not good practice though. I would rather pass the information than destroy the original with the form.
Jun 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5503
by: salih ataoz | last post by:
i close a form and i want to open it again it show me Cannot access a disposed object at vb6 this is ok at comman1_click form1.show
1
1449
by: amber | last post by:
Hello, I have a parent form, with a menu item used to open the child form. If I open the child form, then close it, and try to reopen it from the parent, I get the error message: An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll Additional information: Cannot access a disposed object named "frm1".
5
6134
by: D Witherspoon | last post by:
I use the following code to open up a form. ------------------------------------------------------- If fImage Is Nothing Then fImage = New frmImage End If fImage.Show()
5
8523
by: theinvisibleGhost | last post by:
I'm having a problem that occurs at random in my app. I get an exception "Cannot Access a disposed object" In MSCorLib when calling boolean Change (int32, int32) Stack trace reveals System.Threading.Timer.Change(Int32, int32) at Systems.Timers.UpdateTimer() at System.Timers.Timer.set_Interval(double value)
5
6114
by: mthgk | last post by:
I have a C# MDI app. The child forms do alot of work, so this work is perfomed on a different thread created using ThreadPool.QueueUserWorkItem(). Because the status of the work is important to the user, I post the results in a richTextBox on the child form. I have created an event to do this since it is best to update the controls using the thread that they were created with (or so I've read). Anyway, the first time the user selects a...
7
2790
by: ed | last post by:
Hi, Here's my code 'in form WithEvents formReplace As New Form Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Clic formReplace.Show(
1
1986
by: Jesper | last post by:
Hi, In visual studio 2003 I made an application that ran without problems on a number of 50+ machines (all running .Net 1.1). Now I've recompiled the program using Visual studio 2005, .Net 2.0 has been installed on all machines, completely updated from windowsupdate.com. On two mahines however theres a problem, I get this error: Cannot Access a disposed object. Object name: 'Button'.
1
2247
by: Amit Dedhia | last post by:
Hi I am having problem working with Timers in C++/CLI (the .NET version of C++) I have an application which has several forms with pictureBox controls on it. There is a background timer executing every 250ms and it generates a display image (using some real time data) and pastes those on the picture box. As the picturebox was generated by main application thread, I used 'control.Invoke()' in the timer function
4
10333
JustRun
by: JustRun | last post by:
Hi All, I'm developing a windows desktop solution using VC# , I deal with my database using Dataset. My Problem that i'm trying to call a Form to display a confirmation message after every Save, Delete ...., I wanted to make my own Message box, it works well but for one time only, if i tried to call it more than one time it gives me this exception: <Cannot access a disposed object. Object name: 'frmMsg'.> My Code:
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.