Solved

VB .net XML parser not closing

Posted on 2011-03-03
6
450 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 74

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now