Close or Dispose

  • Thread starter Thread starter Miha Markic
  • Start date Start date
M

Miha Markic

Hi Pablo,

I think the difference is mostly when Form is shown as modal.
In that case, the close does destroy the instance (it does when form is
being shown modaless) - it should be destroyed by calee with calling
Dispose.
 
Hi people!!.
Which is diference between to use method CLOSE and DISPOSE to close a form?

Tx.
Pablo Salazar
 
Pablo,

The Close method is going to end up disposing the form (for the most
part). You can call the two interchangably.

Hope this helps.
 
I was under the impression that the close() actualy called (behind the
scenes) the dispose(). Am I wrong?

Marco
 
Hello,

This is what MSDN says (for Form.Close()):

"When a form is closed, all resources created within the object are closed
and the form is disposed."

So, I suppose you are correct.

--
Regards,
Kristofer Gafvert - IIS MVP
Reply to newsgroup only. Remove NEWS if you must reply by email, but please
do not.
www.ilopia.com - FAQ and Tutorials for Windows Server 2003
 
Kristofer and Marco,

To be more specific, calling the Close method on the Form is going to
send a WM_CLOSE message to itself. When the Form gets that message, it will
close the form, and call Dispose on itself (except in the case when it is
shown as a modal dialog, I believe).

The only difference in the case of calling Close over Dispose is that
calling Close will cause the Closing event to fire, in which case listeners
on the event can cancel the close operation.
 
You are right except that it can be changed to do what ever the person
wants. So a malicious programmer could override close() and then whenever
it is called catch that and prevent the program from closing.
 
Nick said:
You are right except that it can be changed to do what ever the person
wants. So a malicious programmer could override close() and then whenever
it is called catch that and prevent the program from closing.

The same with Dispose(). It is not a requirement to call base.DoDispose() each time ;)
 
i don't get this "malicious programmer" stuff. i know bad programmer, i
know bug prone, but is this a reference to some sort of devil in each of us?

which brings us to the question of close/ dispose generally: is closing a
file stream generally enough? what about bitmaps and images, what resources
need to be explicitly disposed, implicitly disposed and when? where is the
subtext that tells you what you "should be" doing and what you can safely
ignore?
 
Hi,

WoodBeeProgrammer said:
i don't get this "malicious programmer" stuff. i know bad programmer, i
know bug prone, but is this a reference to some sort of devil in each of us?

which brings us to the question of close/ dispose generally: is closing a
file stream generally enough? what about bitmaps and images, what resources
need to be explicitly disposed, implicitly disposed and when? where is the
subtext that tells you what you "should be" doing and what you can safely
ignore?

Documentation should tell you.
Furthermore, if the class implements IDispose it is not bad if you call
Dispose.
 
doh! (why didnt i think of that). thanks miha

When is code rush releasing? will there be a discount for newsgroup
subscribers (jk-- just kidding). will it be extensible (so i can add my
personal indiosyncracies using c# rather than macro recordings).
 
WoodBeeProgrammer said:
doh! (why didnt i think of that). thanks miha

Simple things are the best :)
When is code rush releasing?

I guess soon - don't know for sure. However, if you are a subscriber to
DevExpress there is a release candidate available.

will there be a discount for newsgroup
subscribers (jk-- just kidding).

Yes, yes. You will have 10 newsgroup posts for free ;-)

will it be extensible (so i can add my
personal indiosyncracies using c# rather than macro recordings).

CodeRush is a totaly extensible and modular - you won't believe how easy is
to build plugins, templates, and stuff.
I might be biased, but when you see it you will understand :)
 
Back
Top