Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB .net XML parser not closing

Posted on 2011-03-03
6
Medium Priority
?
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

618 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