Results 1 to 10 of 10

Thread: [RESOLVED] [2008] Application Exits Prematurely

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Resolved [RESOLVED] [2008] Application Exits Prematurely

    I have a module that is set to be the "main" thing that loads so it goes through a process of parsing through an XML file but as soon as it is completed the application exits even when i tell it to load the first form :S any ideas why?
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  2. #2
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: [2008] Application Exits Prematurely

    Try debugging the code line by line and see what's going on. That is the best advice I can give you without seeing the code.
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: [2008] Application Exits Prematurely

    So the program starts with a Sub Main? At some point you show the first form. Do you show that form using Show? If so, that's the problem, as Show doesn't block, so the Sub Main will run to the End Sub, at which point your app ends. This was a more common issue in 2003, where everyone used Sub Main by default. The easy way around this is ShowDialog, but that will have other problems, depending on how the code is set up. There is a more complicated solution, but I'll leave it out for now, as I have made enough assumptions so far.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: [2008] Application Exits Prematurely

    This is my module at the moment:
    vb Code:
    1. Imports System.IO
    2. Imports System.Xml
    3. Module Module_Main
    4.  
    5.     Sub Main()
    6.         Try
    7.             'Check for the existence of the file before proceeding.
    8.             If Not IO.File.Exists(Application.StartupPath & "/Patch.xml") Then
    9.                 MsgBox("Cannot find patch file!")
    10.                 Exit Sub
    11.             End If
    12.  
    13.             Dim m_xmlr As XmlTextReader
    14.  
    15.             'create the XML reader
    16.             m_xmlr = New XmlTextReader(Application.StartupPath & "/Patch.xml")
    17.  
    18.             'Disable whitespace so that you don't have to read over whitespaces
    19.             m_xmlr.WhitespaceHandling = WhitespaceHandling.None
    20.  
    21.             'read the xml declaration and advance to family tag
    22.             m_xmlr.Read()
    23.  
    24.             'read the family tag
    25.             m_xmlr.Read()
    26.  
    27.             'Load the Loop
    28.             While Not m_xmlr.EOF
    29.                 'Go to the name tag
    30.                 m_xmlr.Read()
    31.  
    32.                 'if not start element exit while loop
    33.                 If Not m_xmlr.IsStartElement() Then
    34.                     Exit While
    35.                 End If
    36.  
    37.                 'Get the file name attribute
    38.                 Dim FILENAMEAttribute = m_xmlr.GetAttribute("filename")
    39.  
    40.                 'Read elements Size and Checksum
    41.                 m_xmlr.Read()
    42.  
    43.                 'Get the SIZE Element
    44.                 Dim SIZEValue = m_xmlr.ReadElementString("SIZE")
    45.  
    46.                 'Get the CHECKSUM Element
    47.                 Dim CHECKSUMValue = m_xmlr.ReadElementString("CHECKSUM")
    48.  
    49.                 'Return Information
    50.                 MsgBox("FILENAME: " & FILENAMEAttribute _
    51.                    & " SIZE: " & SIZEValue & " CHECKSUM: " _
    52.                   & CHECKSUMValue)
    53.                 ' Console.Write(vbCrLf)
    54.             End While
    55.             'close the reader
    56.             m_xmlr.Close()
    57.         Catch ex As Exception
    58.             MsgBox(ex.ToString)
    59.             Exit Sub
    60.         End Try
    61.         Form1.Show()
    62.     End Sub
    63. End Module

    Right now its just parsing an XML file with a loop and getting information. I call Form1.Show() at the end to load the main form for the application but it just exits the app. What can i use to fix this problem in my case?
    Last edited by youngbucks; Dec 21st, 2008 at 11:14 AM.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: [2008] Application Exits Prematurely

    why not just make this a form application and move the code to the form load event?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: [2008] Application Exits Prematurely

    When i use a form for some reason it takes longer (The full patch file contains alot of information) and this is going to be added to a patching process to replace my current one. I want it to check the files first and if it needs patching load the patcher and if it doesnt load the executable for the game.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: [2008] Application Exits Prematurely

    If all you are going to do is show the one form, then Form1.ShowDialog will solve your problem. Show doesn't block the current execution, and the application ends when Sub Main exits, regardless of whether or not there are other forms being displayed. Therefore, you can't reach the end of Sub Main until you are ready to. ShowDialog will block Sub Main until Form1 is hidden.

    This will work as long as Form1 is intended to stay open for the duration of the program. If that is not the case, then you need a slightly more elaborate construct, but if Form1 will remain open for the duration, then the ShowDialog is all you need.
    My usual boring signature: Nothing

  8. #8
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Re: [2008] Application Exits Prematurely

    Looks like you close the form before you even load the other one? And closing the main startup form will end your application, use .hide

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: [2008] Application Exits Prematurely

    Thanks Shaggy Form1.Showdialog() is what i needed because the form will only temporarily show to update then launch the game, thank you
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: [RESOLVED] [2008] Application Exits Prematurely

    If you close Form1, then ShowDialog won't be enough (unless you load something else immediately afterwards), as closing Form1 will cause ShowDialog to return, at which point Sub Main will exit and the app will terminate.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width