By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,699 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,699 IT Pros & Developers. It's quick & easy.

Dispose() called on Forms

P: n/a
Hi All,
I've recently attempted to upgrade a significantly large app to .net.
Having removed several hundred errors along the way I have now hit a
problem that I'm struggling to find a way around. The problem is this:

The app starts by performing a host of load up sequences (opening
databases, files etcs). Once finished a number of forms are created
and displayed. However, withing a few seconds of the forms being
displayed each forms resepctive dispose() function is called and the
app terminates. I've ploughed through the code and can't find any
clean up calls. The forms are created and shown as follows
dim someFrm as New frm2
someFrm.Show()
I assume the cause is one of the following:
1) an error is causing the app to terminate (I've been running in debug
but no errors are reported!)
2) the forms are somehow going out of scope!?
If anyone could supply me with some helpful pointers I'd be most
grateful
Simon

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

si******@ntlworld.com wrote:
Hi All,
I've recently attempted to upgrade a significantly large app to .net.
Having removed several hundred errors along the way I have now hit a
problem that I'm struggling to find a way around. The problem is this:
The app starts by performing a host of load up sequences (opening
databases, files etcs). Once finished a number of forms are created
and displayed. However, withing a few seconds of the forms being
displayed each forms resepctive dispose() function is called and the
app terminates.


I'm gonna take a guess here that your 'startup object' is a Sub Main,
and that the last thing you do in the Sub Main is .Show your forms,
then End Sub.

There is a significant change of behaviour from VB6 to VB.NET as
regards application lifetime. VB6 would keep running so long as any
Form was loaded, but VB.NET, if started with a Sub Main, will end the
application as soon as that Sub is ended. Or if the startup object is a
form, as soon as that form closes (regardless of any other forms being
open).

Quick fix:

At the end of Sub Main when you have done all your startup work and
want to 'just run', do

Application.Run()

This starts a Windows message pump running that will continue even
after Main is exited. Once you have done this, you will need to use
Application.Exit() to end execution.

--
Larry Lard
Replies to group please

Nov 21 '05 #2

P: n/a
Thanks for the reply Larry.

My startup object is in fact a form class and not main(). This form is
opened and execution is passed to a load up sequence after which lots
of other forms are opened. The first thing to execute is 'new' in the
startup form hence creating an instance of this object - I therefore
assume (I'm a C++ programmer and understand that .NET is more inline
with C++ concepts) that all forms that are later defined and show are
in essence 'children' of the startup form, i.e. the 'child' forms will
only have a lifetime equal to the 'parent' form!? Perhaps I should be
checking that the instance of the startup form remains in scope?

Nov 21 '05 #3

P: n/a
Yes, as soon as the form set as your startup form closes, your
application will end unless you have transferred the message loop else
where with Application.Run, so that could be it if eg your startup form
is a splash screen or similar

--
Larry Lard
Replies to group please

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.