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

Arguments in a thread

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?
0
broadbent
Asked:
broadbent
1 Solution
 
arif_eqbalCommented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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