views:

40

answers:

2

Running into problems creating objects through reflection and then running them on multiple threads.

I just cannot seem to figure out what I need to here:

            For Each WorkerNode As XmlNode In oRunSettings.GetWorkerValues
                Dim sWorkerName = WorkerNode.Attributes(SETTING_NAME_ID).Value
                Dim oWorkerType As Type = Type.GetType(String.Format("Worker.{0}", sWorkerName))
                Dim oWorker As Object = Activator.CreateInstance(oWorkerType)
                Dim tWorker As Thread = New Thread(AddressOf oWorker.Process)
                tWorker.Start()
            Next

It is causing errors at the "AddressOf" because Object does not have a method called that. Do I need to do something with an interface?

+1  A: 

First of all I want to say that I've never wrote code in VB so I can be completely wrong here but I'll try anyway.

It seems that you hold the created instance as Object instead of it's correct type. Object does not contain method named Process, hence the error.

try casting the object to the correct type.

Moshe Levi
I think that is the next thing I would try... though the latebinding might still have caused problems.
IPX Ares
A: 

I hate when people answer their own question, but while waiting for an answer, I realized that I could just cast the object as its base object, and set the reflection from there. That is working now.

IPX Ares