Arguments in a thread

Posted on 2006-05-16
Last Modified: 2010-04-23
I am reading an xml file and it is taking a very long time to parse.
It contains a number of fields, each one being an entry in a database.
I thought therefore to create a separate thread for each entry.

Dim xbn, xin as MSXML2.IXMLDOMNode
Dim xthread as Threading.Thread
Dim xread as new xmlThread

For each xin In xbn.childNodes
With xread
 .xin = xin
 xthread = New Threading.Thread(AddressOf .ReadXML)
End With

Class xmlThread
Friend xin as MSXML2.IXMLDOMNode

Friend Shared Sub ReadXML()
Dim xan as MSXML2.IXMLDOMNode
For each xan in xin.ChildNodes

VS returns an error 'cannot refer to an instance member of a class from within a shared method' etc

How do I deal with this please?
Question by:broadbent
    LVL 19

    Accepted Solution

    Do not have the function ReadXML as shared
    Also, I see you using only one instance of the class xmlThread, so the field xin of the same instance is being changed.
    There's no guarantee that Function ReadXML would get unique values of xin in different Threads
    So use a new instance for each Thread
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    To pass arguments to a Thread, encapsulate the Thread in a Class and pass those values to the Class.  The thread will be able to access the members of the class.   In this way, each thread can have its own set of values...

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    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.
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now