By some reason, the suggested method is using
System.Threading.ParameterizedThreadStart
.
I never do this! You have to pass a
System.Object
argument, so run-time time would be of some container for all your parameters (
struct
, for example); and in the thread code you need to cast
System.Object
back to your structure, which is unsafe.
I never understood why doing such ugly things. There is a much better way. All you need is to pass "Me" reference. I wrap whole thread in some class and create a method the thread should be started with I call
Body
. I make it and instance (non-static) method, without parameters (important!). Using a regular constructor
System.Threading.Thread(ThreadStart)
allows to pass
Body
.
As
Body
is an instance method, all members of the wrapper class are passed through the invisible parameter "
Me
" of the type of the wrapper class; and this parameter is passed invisibly to
Body
. There is nothing unusual about it — this is how all instance methods work. But as a result, the method of the wrapper
Body
is started in a thread and all members of the instance of the member class are visible inside the method. So, you instantiate the wrapper class first. All parameters mentioned in your Question should be members of the wrapper. You need to initialize them before
Thread.Start
. For example, you can pass all those values in the wrapper's constructor.
I have a complete code sample, but it is in C#:
How to pass ref parameter to the thread[
^].
Nevertheless it's quite easy to understand how it work using my explanation.
Good luck,
—SA