• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Things to do when mdiform is closing.

Hi,

What I should do to clean up everything when mdiform is closed by user?

Thank you.
0
emi_sastra
Asked:
emi_sastra
  • 4
  • 3
1 Solution
 
vb_jonasCommented:
Hi, what do you mean by clean up everything? Finishing Database operations? disposing Graphics? Closing open files? All depends on what you have in your app.
0
 
emi_sastraAuthor Commented:
Hi,

Yes. For mdiform with several windows form and using database (dataset, datatable and etc).

For specific, how to clean:

1. Still open Forms.
2. Close Database  (dataset, datatable and etc).
3. etc that beside point 1 and 2 for common application.

Thank you.
0
 
vb_jonasCommented:
Hi!

1. Still open forms will be closed automatically and if you need to do cleanup in those forms you should add code to the FormClosing - event.

If you need to close or do something else on the mdi-children by code from mdi parent you can do it by looping mdichildren (from the mdi parent form):

        Dim f As Form
        For Each f In Me.MdiChildren
            f.Close()
        Next

2. Close database connections / update should be called, generally from the object which opened the connection/edited the data, sometimes could be done in the mdi. It also depends on what your app is doing. Are you opening connections from the mdi-parent?

3. Everything should really be cleaned up on the best place, if you are opening a file in a sub on a form, that same sub should close it. et. cetera. If you are greating graphics you should dispose it from the same routine.

Hope this helps a bit at least.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
emi_sastraAuthor Commented:
Hi Jonas,

Point 1, I get it.

Point 2. Any idea when to open connection?

Point 3. If I create picturebox and load it images in some forms at runtime, what should I do to clean it?

Thank you.
0
 
vb_jonasCommented:
Point 2. If you use DataAdapters it takes care of opening and closing the connection for you. If you for example are using DataReaders, och Commands you handle connections manually. One way is to open just before reading/writing, and closing after data processing is done. But if you use a global connection object you can open it in your startup form, perhaps in Form_Load(). And you close it in Form_FormClosing().

Point 3. no need for that, .net takes care of it.
0
 
emi_sastraAuthor Commented:
Hi Jonas,

I quite understand now.

Thank you very much for your help.
0
 
vb_jonasCommented:
You are very welcome!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now