• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • Last Modified:

VB .net XML parser not closing

Hi All
so my piece of code is working however, lets say it is reading the xml and there are repeating tables it will get the info and wait until i click a checkbox to show me the rest, here is the problem lets say the xml document has 4 repeating tables and i close the app on the second one
the app GUI closes but it is still running in the back ground. any ideas how i can make it complety close?
Try

            Dim m_xmld As XmlDocument
            Dim m_nodelist As XmlNodeList
            Dim m_node As XmlNode
            'Create the XML Document
            m_xmld = New XmlDocument()
            Dim mgr As New XmlNamespaceManager(m_xmld.NameTable)
            'Load the Xml file
            m_xmld.Load(textboxFileToOpen.Text)
            mgr.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-12-29T14:17:33")
            'Get the list of name nodes 
            m_nodelist = m_xmld.SelectNodes("//my:group2", mgr)
            'Loop through the nodes
            For Each m_node In m_nodelist

                'Get the firstName Element Value
                Dim lastNameValue = m_node.ChildNodes.Item(0).InnerText
                'Get the lastName Element Value
                Dim firstNameValue = m_node.ChildNodes.Item(1).InnerText
                Dim companyname = m_node.ChildNodes.Item(2).InnerText
                Dim description = m_node.ChildNodes.Item(3).InnerText
                Dim emailaddy = m_node.ChildNodes.Item(4).InnerText
                Dim memberof = m_node.ChildNodes.Item(5).InnerText
                Dim primarygroupid = m_node.ChildNodes.Item(6).InnerText
                Dim manager = m_node.ChildNodes.Item(7).InnerText
                Dim department = m_node.ChildNodes.Item(8).InnerText
                Dim password = m_node.ChildNodes.Item(9).InnerText
                'Write Result to the Console
                'MsgBox("FirstName: " & firstNameValue & " LastName: " _
                ' & lastNameValue & " Company Name: " & companyname & " Desc: " & description & " Email Addy: " & emailaddy)
                '  Console.Write(vbCrLf)
                textboxlastName.Text = lastNameValue
                textboxfirstName.Text = firstNameValue
                textboxcompanyName.Text = companyname
                textboxDescription.Text = description
                textboxEmailAddress.Text = emailaddy
                'TextBoxmemberof.text = memberof
                'textboxprimarygroup.text = primarygroupid
                textboxManager.Text = manager
                textboxDepartment.Text = department
                textboxPassword.Text = password
               
         
                checkboxnext.Checked = False


                Do Until checkboxnext.Checked = True
                    Threading.Thread.Sleep(1000)
                Loop

            Next

        Catch errorVariable As Exception
            'Error trapping
            MsgBox(errorVariable.ToString())
        End Try

Open in new window

0
EfrenM
Asked:
EfrenM
  • 3
  • 2
1 Solution
 
käµfm³d 👽Commented:
Is this a multi-threaded app? Are you using any sort of Thread, BackgroundWorker, or ThreadPool objects elsewhere to run the above code?
0
 
wdosanjosCommented:
I think you need to create a flag that indicates that the application is closing.  You set the flag when the application closes and then test it in your loop.  It would be something like this:

Private Shared isAppClosing As Boolean = False ' In Your Class

... (when app closes)

isAppClosing = True

...

Open in new window


                ...

                Do Until checkboxnext.Checked = True Or isAppClosing 
                    Threading.Thread.Sleep(1000)
                Loop

                If isAppClosing Then
                    Exit For
                End If

            Next

                ...

Open in new window


I hope this helps.
0
 
EfrenMAuthor Commented:
@kaufmed: yes it has threads Private Pause As New Threading.ManualResetEvent(True)

@wdosanjos: it worked on my context menu below is the code, any idea how to make it detect when i press the X button on the top right hand side?


Private Sub TestToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestToolStripMenuItem.Click
        isAppClosing = True
        Application.Exit()
    End Sub

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
EfrenMAuthor Commented:
duh i got

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        isAppClosing = True
        Application.Exit()
    End Sub

Open in new window

0
 
EfrenMAuthor Commented:
thank you, saved me a headache :)
0
 
wdosanjosCommented:
You can handle that on the form's FormClosing event.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now