-
Dec 21st, 2008, 09:58 AM
#1
Thread Starter
Hyperactive Member
[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?
-
Dec 21st, 2008, 10:37 AM
#2
Frenzied Member
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
-
Dec 21st, 2008, 10:48 AM
#3
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
-
Dec 21st, 2008, 11:11 AM
#4
Thread Starter
Hyperactive Member
Re: [2008] Application Exits Prematurely
This is my module at the moment:
vb Code:
Imports System.IO Imports System.Xml Module Module_Main Sub Main() Try 'Check for the existence of the file before proceeding. If Not IO.File.Exists(Application.StartupPath & "/Patch.xml") Then MsgBox("Cannot find patch file!") Exit Sub End If Dim m_xmlr As XmlTextReader 'create the XML reader m_xmlr = New XmlTextReader(Application.StartupPath & "/Patch.xml") 'Disable whitespace so that you don't have to read over whitespaces m_xmlr.WhitespaceHandling = WhitespaceHandling.None 'read the xml declaration and advance to family tag m_xmlr.Read() 'read the family tag m_xmlr.Read() 'Load the Loop While Not m_xmlr.EOF 'Go to the name tag m_xmlr.Read() 'if not start element exit while loop If Not m_xmlr.IsStartElement() Then Exit While End If 'Get the file name attribute Dim FILENAMEAttribute = m_xmlr.GetAttribute("filename") 'Read elements Size and Checksum m_xmlr.Read() 'Get the SIZE Element Dim SIZEValue = m_xmlr.ReadElementString("SIZE") 'Get the CHECKSUM Element Dim CHECKSUMValue = m_xmlr.ReadElementString("CHECKSUM") 'Return Information MsgBox("FILENAME: " & FILENAMEAttribute _ & " SIZE: " & SIZEValue & " CHECKSUM: " _ & CHECKSUMValue) ' Console.Write(vbCrLf) End While 'close the reader m_xmlr.Close() Catch ex As Exception MsgBox(ex.ToString) Exit Sub End Try Form1.Show() End Sub 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.
-
Dec 21st, 2008, 12:02 PM
#5
Re: [2008] Application Exits Prematurely
why not just make this a form application and move the code to the form load event?
-
Dec 21st, 2008, 12:16 PM
#6
Thread Starter
Hyperactive Member
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.
-
Dec 21st, 2008, 03:43 PM
#7
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
-
Dec 21st, 2008, 03:47 PM
#8
Hyperactive Member
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
-
Dec 21st, 2008, 03:51 PM
#9
Thread Starter
Hyperactive Member
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
-
Dec 21st, 2008, 04:34 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|