473,323 Members | 1,550 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,323 software developers and data experts.

Dispose() called on Forms

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
3 1098

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Cybertof | last post by:
Hi ! I thought the GC was doing the job of cleaning ressources.... Do you know why Microsoft is using Dispose in this sample ? public void ShowMyDialogBox() { Form2 testDialog = new...
19
by: Nathan | last post by:
I know this has been asked previously, but I've run into a situation where I need to know the difference between close and dispose, and I can't get the information I need from msdn help or previous...
9
by: Charles Law | last post by:
I have a form on which user controls are placed at runtime. When a control is added to the form a handler is added for an event that a high-level object raises, which must be handled by the new...
156
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created...
9
by: Geoff Callaghan | last post by:
I have several functions that require doing a New on a local object. If the object is local to a sub or function, do I need to dispose of it, or will it just go away like any other local variable?...
0
by: Jeff | last post by:
Banging my head against the wall trying to figure this out. I have a 'sometimes' hang while disposing a form which contains an ActiveX control (Flash.ocx version 7). The form's Dispose() method...
1
by: Flack | last post by:
Hey guys, I'm having some weird issues when calling Dispose on one of the controls in a user control from an asycn or sync method. When called form an async method Dispose makes a call to...
71
by: active | last post by:
In the main program I check to see if a certain form has been disposed. Does it make sense in that form's FormClosed event to do: Me.Dispose to make sure it is disposed the next time I check. Or...
19
by: rbrowning1958 | last post by:
Hello, I am confused by dispose etc. and hope someone can set me right. 1. The Dispose(Bool) the IDE generates for a form has nothing to do with IDisposable, right? 2. So when is this called?...
0
by: Smokey Grindel | last post by:
I get this error every so often and very randomly... Exception Information: System.InvalidOperationException: Value Dispose() cannot be called while doing CreateHandle(). at...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.