Creating threads on the fly and passing parameters

If I have some sub routine code like:

dim t as new thread AddHandler, WeakAddressOf SomeFunction

I know SomeFunction in this example has to have a parameter like:

Sender as thread

How do I set it up to pass additional parameters to my function without getting a delegate error on compile?

You would have to create a subclass of Thread and add a method with additional parameters, which in turn calls .Run


Seems more cumbersome. Any noticeable advantage to that than, say, having some private/protected properties for the thread to access that are stand-ins for parameter passing? Granted I know this can lead to similar results as if I were passing a parameter by reference.

I suppose it’s just how deeply I want to encapsulate.

The advantage would be encapsulation, which would allow you to have more than one such thread running at a time. You shouldn’t share global variables between threads.

In this particular instance it’s already encapsulated by a class, so all the parameters are private, but I understand what you mean.

I basically have a class with one method I can call from the main thread and then it creates threads on the fly to read a gzipped file, process it, and rezip it. The thread is assigned to each of the three functions serially so 1) keeps the UI responsive and 2) it can report a state (running/not running) for each section of functionality. No need for another level of encapsulation as I don’t see any access conflicts.