(VB.Net, framework 2.0) Passing data to child threads - how? - TechRepublic
Question
July 8, 2011 at 12:43 PM
adev73

(VB.Net, framework 2.0) Passing data to child threads – how?

by adev73 . Updated 14 years, 11 months ago

Imagine, if you will, a vb.net object which is handed a lump of data (in text format); which reads a few database tables, does a bit of internal state management, and 1s +/- 0.5s later spits out some XML which will later be sent out across the network.

Now imagine 20 of those objects. Each one takes the same input data, but will output subtly (sometimes wildly) different results depending on the database contents & internal state.

Currently, each object is given its data in turn, and the resulting XML is stored away in a variable. Once the loop is complete, the resulting XML is compressed and sent across the network. Usually, the loop is pretty quick, but obviously the more objects, the slower it gets, in a linear relationship.

What I would like to do is; to split each object out onto its own thread. Each thread would be simultaneously passed the same input data, and left to its own devices. Instead of passing the XML back to the caller, it will be compressed and transmitted by the object itself.

Where I am having brain-fade, is trying to work out how to send the data to each thread… Ideally, I’d like to be able to call a sub, e.g. SendDataToThreads(myData as string) which places the data into each thread (or, maybe, into some shared memory that all threads can access), and then triggered an event in each thread that causes it to do its thing. Depending on the source, data could arrive every fraction of a second, through to once every 10 or even 30 seconds. Ideally, the subthreads would (upon receiving a “go!” command), just do their thang until they finish, then start looking for updates.

Any thoughts? All of the examples I’ve seen are designed to allow child threads to talk back to the main thread; which is basically the opposite of what I’m after…

This discussion is locked

All Comments