473,378 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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=SomeControlOntheForm.text
This seems to work. But am not sure that it is waterproof.
Thanks,
Boni
Nov 21 '05 #1
7 5216
"Boni" <oilia@nospam> schrieb:
if I do myform.close() is it disposed or not?
is it correct do following?
myForm.close()
Info=SomeControlOntheForm.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*************@TK2MSFTNGP09.phx.gbl...
"Boni" <oilia@nospam> schrieb:
if I do myform.close() is it disposed or not?
is it correct do following?
myForm.close()
Info=SomeControlOntheForm.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**************@TK2MSFTNGP15.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*************@TK2MSFTNGP09.phx.gbl...
| > "Boni" <oilia@nospam> schrieb:
| >> if I do myform.close() is it disposed or not?
| >> is it correct do following?
| >> myForm.close()
| >> Info=SomeControlOntheForm.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***************@TK2MSFTNGP09.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**************@TK2MSFTNGP15.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***************@TK2MSFTNGP09.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
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...
1
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...
3
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...
3
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...
5
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...
2
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...
44
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...
5
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...
3
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.