Dispose() called on Forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • simon_w3@ntlworld.com

    #1

    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

  • Larry Lard

    #2
    Re: Dispose() called on Forms


    simon_w3@ntlwor ld.com wrote:[color=blue]
    > 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[/color]
    this:[color=blue]
    >
    >
    >
    > 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.[/color]

    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.Exi t() to end execution.

    --
    Larry Lard
    Replies to group please

    Comment

    • simon_w3@ntlworld.com

      #3
      Re: Dispose() called on Forms

      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?

      Comment

      • Larry Lard

        #4
        Re: Dispose() called on Forms

        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

        Comment

        Working...