Things to do when mdiform is closing.

Hi,

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

Thank you.
LVL 1
emi_sastraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
emi_sastraAuthor Commented:
Hi Jonas,

I quite understand now.

Thank you very much for your help.
0
vb_jonasCommented:
You are very welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.