Solved

VB .net XML parser not closing

Posted on 2011-03-03
6
454 Views
Last Modified: 2012-05-11
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
Comment
Question by:EfrenM
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35029370
Is this a multi-threaded app? Are you using any sort of Thread, BackgroundWorker, or ThreadPool objects elsewhere to run the above code?
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 35029386
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
 
LVL 2

Author Comment

by:EfrenM
ID: 35031364
@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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:EfrenM
ID: 35031443
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
 
LVL 2

Author Closing Comment

by:EfrenM
ID: 35031448
thank you, saved me a headache :)
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35031514
You can handle that on the form's FormClosing event.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now