Home All Groups Group Topic Archive Search About

Weird application exit

Author
30 Mar 2010 5:04 AM
Anthony
So I've got my application starting by calling Sub Main() which checks for
the existence of files and will load one of two screens depending on if the
files are present or not. The problem is that when it loads the screen, the
application immediately terminates. I'm suspecting that this is because the
end of Sub Main() is reached but I can't be sure. Here is the entire code of
Sub Main(). Can anyone tell me what might be the problem:

  Sub Main()
        If (Not File.Exists(AppConfFolderPath & "\config.dat")) Then
            MsgBox("Entered the first part of the if clause")
            ConfigScreen.Show()
            MsgBox("The ConfigScreen was just called")
        Else
            Dim oFile As StreamReader
            Try
                MsgBox("Entered the try/catch block")
                oFile = New StreamReader(AppConfFolderPath & "\config.dat")
                Username = oFile.ReadLine
                Password = oFile.ReadLine
                oFile.Close()
                oFile = Nothing
                MainForm.Show()
            Catch ex As Exception
                ConfigScreen.Show()
            End Try
        End If
    End Sub

Note that neither ConfigScreen or MainForm have any exit or hide calls.

Thanks!
Anthony

Author
30 Mar 2010 5:36 AM
Tom Shelton
On 2010-03-30, Anthony <anth***@adcl.us> wrote:
> So I've got my application starting by calling Sub Main() which checks for
> the existence of files and will load one of two screens depending on if the
> files are present or not. The problem is that when it loads the screen, the
> application immediately terminates. I'm suspecting that this is because the
> end of Sub Main() is reached but I can't be sure. Here is the entire code of

You are suspecting correctly.  You need to use MainForm.ShowDialog or
Application.Run (MainForm).  Because, you are not starting a message loop with
show, so the form immediately closes and your application ends.

I personally would call Application.EnableVisualStyles() sometime before you
call show as well - just so your application gets themed correctly :)


--
Tom Shelton
Author
30 Mar 2010 6:04 AM
Anthony
Show quote Hide quote
"Tom Shelton" <tom_shel***@comcastXXXXXXX.net> wrote in message
news:eglvDs8zKHA.244@TK2MSFTNGP06.phx.gbl...
> On 2010-03-30, Anthony <anth***@adcl.us> wrote:
>> So I've got my application starting by calling Sub Main() which checks
>> for
>> the existence of files and will load one of two screens depending on if
>> the
>> files are present or not. The problem is that when it loads the screen,
>> the
>> application immediately terminates. I'm suspecting that this is because
>> the
>> end of Sub Main() is reached but I can't be sure. Here is the entire code
>> of
>
> You are suspecting correctly.  You need to use MainForm.ShowDialog or
> Application.Run (MainForm).  Because, you are not starting a message loop
> with
> show, so the form immediately closes and your application ends.
>
> I personally would call Application.EnableVisualStyles() sometime before
> you
> call show as well - just so your application gets themed correctly :)

Thanks Tom! Much appreciated.
Hadn't thought about the Application.EnableVisualStyles() call either.

Anthony