473,739 Members | 4,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

when is the form disposed?

Dear all,
if I do myform.close() is it disposed or not?
is it correct do following?
myForm.close()
Info=SomeContro lOntheForm.text
This seems to work. But am not sure that it is waterproof.
Thanks,
Boni
Nov 21 '05 #1
7 5229
"Boni" <oilia@nospam > schrieb:
if I do myform.close() is it disposed or not?
is it correct do following?
myForm.close()
Info=SomeContro lOntheForm.text
This seems to work. But am not sure that it is waterproof.


It depends on how you show your form. When showing it by calling its 'Show'
method and closing it using its 'Close' method, the form will be disposed.
However, if you show your form using 'ShowDialog', it won't be disposed
automatically when it gets closed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Dear Herfried,
1. what is the idea behind the dependency of destruction from the method,
how the form shown?
2. what is the good practice of taking data from the form. Should this be
done in OnFinish button handler?

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schrieb im Newsbeitrag
news:OO******** *****@TK2MSFTNG P09.phx.gbl...
"Boni" <oilia@nospam > schrieb:
if I do myform.close() is it disposed or not?
is it correct do following?
myForm.close()
Info=SomeContro lOntheForm.text
This seems to work. But am not sure that it is waterproof.


It depends on how you show your form. When showing it by calling its
'Show' method and closing it using its 'Close' method, the form will be
disposed. However, if you show your form using 'ShowDialog', it won't be
disposed automatically when it gets closed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Boni,
| 1. what is the idea behind the dependency of destruction from the method,
| how the form shown?
Form.Show (inherited from Control.Show) shows the form modelessly. The code
that displays the form will continue running while the form is being
displayed.

Form.ShowDialog shows the form as a modal dialog box. The code that displays
the form will wait until the form is closed.

Seeing as its common to set some values, ShowDialog, retrieve some values,
ShowDialog does not do a Dispose so as to allow you to retrieve values of
controls, when you are done retrieving values of controls, you need to call
Dispose.

Because of the indeterminate time when a modeless form is closed, other then
the Close event there is no real chance to call Dispose on the form...

| 2. what is the good practice of taking data from the form. Should this be
| done in OnFinish button handler?

I normally use Form.ShowDialog , then take any data from the form, then call
Form.Dispose.

For MDI children & other modeless forms, there is some command object
(button, menu, toolbar, etc...) that causes the information to be saved or
the information is implicitly saved by virtue of being bound to a
datasource.

Hope this helps
Jay

"Boni" <oilia@nospam > wrote in message
news:eP******** ******@TK2MSFTN GP15.phx.gbl...
| Dear Herfried,
| 1. what is the idea behind the dependency of destruction from the method,
| how the form shown?
| 2. what is the good practice of taking data from the form. Should this be
| done in OnFinish button handler?
|
| "Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schrieb im
Newsbeitrag
| news:OO******** *****@TK2MSFTNG P09.phx.gbl...
| > "Boni" <oilia@nospam > schrieb:
| >> if I do myform.close() is it disposed or not?
| >> is it correct do following?
| >> myForm.close()
| >> Info=SomeContro lOntheForm.text
| >> This seems to work. But am not sure that it is waterproof.
| >
| > It depends on how you show your form. When showing it by calling its
| > 'Show' method and closing it using its 'Close' method, the form will be
| > disposed. However, if you show your form using 'ShowDialog', it won't be
| > disposed automatically when it gets closed.
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
Nov 21 '05 #4

I normally use Form.ShowDialog , then take any data from the form, then
call
Form.Dispose.

Do I need to destruct it explicitely? If I do not destruct it is it a memory
leak or it is removed by GC, when form variable goes out of scope?
Nov 21 '05 #5
"Boni" <oilia@nospam > schrieb:
I normally use Form.ShowDialog , then take any data from the form, then
call
Form.Dispose.


Do I need to destruct it explicitely? If I do not destruct it is it a
memory leak or it is removed by GC, when form variable goes out of scope?


'Dispose' will be called when the finalizer of the object is called.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6
Boni,
Its best to "destruct" it explicitly by calling its Dispose method.

If you don't then the GC will "destruct" it at the GC's leisure, which may
be "hours" after the fact.

Remember the GC is non-deterministic. When the form variable goes out of
scope allows the GC to collect that object, when & if the GC runs.

Hope this helps
Jay

"Boni" <oilia@nospam > wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
|
|
| > I normally use Form.ShowDialog , then take any data from the form, then
| > call
| > Form.Dispose.
| Do I need to destruct it explicitely? If I do not destruct it is it a
memory
| leak or it is removed by GC, when form variable goes out of scope?
|
|
Nov 21 '05 #7
Thank you Herfried and Jay for clarifying that to me. It was my old doubt.
Now it disapears! Thanks.

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> schrieb im
Newsbeitrag news:uZ******** ******@TK2MSFTN GP15.phx.gbl...
Boni,
Its best to "destruct" it explicitly by calling its Dispose method.

If you don't then the GC will "destruct" it at the GC's leisure, which may
be "hours" after the fact.

Remember the GC is non-deterministic. When the form variable goes out of
scope allows the GC to collect that object, when & if the GC runs.

Hope this helps
Jay

"Boni" <oilia@nospam > wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
|
|
| > I normally use Form.ShowDialog , then take any data from the form, then
| > call
| > Form.Dispose.
| Do I need to destruct it explicitely? If I do not destruct it is it a
memory
| leak or it is removed by GC, when form variable goes out of scope?
|
|

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1861
by: Sean Connery | last post by:
I have a Microsoft UI Process Application Block that is controlling child forms in an MDI parent container. The views node in the app.config file has been set to stayOpen=false. Because there are a series of data entry forms using ONLY the numeric key pad, certain keys on this pad have been configured to behave as "function keys". In order for this to happen, I have implemented the IMessageFilter interface to intercept messages in the...
1
1424
by: SamSpade | last post by:
I need a MDI form to be notified when one of it's child closes. I could define an event in each child and raise it when it closes. But if there is some WinProc message that occurs when a child closes I would rather use it and automate the process. Second question. When a form Closed event occurs is the form then disposed. I want to check the variable that references the form and if the form is
3
1435
by: Dean Slindee | last post by:
When launching another form from the current form, I use the code below to determine if the form to be launched is already active and showing. If form = Nothing, then I instantiate it, otherwise I just set it's properties and refresh the form. Problem is: when the form already been shown and closed using it's X button (sending the form thru it's Closing and Disposed events), and then an attempt is made to reinstantiate it again, the...
3
1176
by: dast | last post by:
Hi, I'm using a delegate to edit some controls on formA from another thread on formB. This works nicely the first time I run formA. But if I close formA and reopen it I get errors. When changing the checked state of a radiobutton I get an error saying that I cannot access the control since it is disposed. But I can still change the
5
4693
by: Michael.Suarez | last post by:
Suppose I have a button on a form that opens up another form. the code in the buttons click event is: frmMyCustomForm frm = new frmMyCustomForm (); frm.ShowDialog(); frm.Dispose(); The form opens, user does what they need, the form closes, and gets
2
3748
by: Mike | last post by:
Hello, Ok I have 2 classes in my project, one is the main form and one is a connection class, at a certain event on my main form a new instance is made of the connection class, and a reference to the main form is passed to its constructor. The connection class opens up a new thread and starts doing work in it, and adds collected data to the main form via a (cross-thread) control invoking delegate.
44
8250
by: Smokey Grindle | last post by:
I have a list box on my form, but I need to databind it to a data table that is a private member of the form's class... so I basically have Public Class MyForm priate m_MyTable as new datatable End Class now where would I properly dispose of this? In the finalize method? I am loading the data for the table in a subroutine that is executed at form load, of course all the commands tied to it are wrapped in using blocks, but
5
5786
by: aine_canby | last post by:
Hi, The problem is that the line - this.Invoke(new MyDelegate(Function), args); // this = MainForm is being called after the line - terminatePopulate = true; therefore I get an exception which states that MainForm has been disposed when this.Invoke is called...
3
1237
rizwan6feb
by: rizwan6feb | last post by:
I know the problem but can't find the solution. Please help I have 2 forms in my application (Form1 and Form2, Form1 is the startup form). I am connecting to the database in a new thread (In the FormLoad event of Form1, please see the code below) . If the connection to database on line# 4 fails i show Form2 (Which is basically a DB settings Form) but the form is disposed when the thread completes . How can make Form2 stay on the screen....
0
8969
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
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
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
6754
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
6054
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
4570
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...
1
3280
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

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.