By some reason, the suggested method is using
I never do this! You have to pass a
argument, so run-time time would be of some container for all your parameters (
, for example); and in the thread code you need to cast
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
. I make it and instance (non-static) method, without parameters (important!). Using a regular constructor
allows to pass
is an instance method, all members of the wrapper class are passed through the invisible parameter "
" of the type of the wrapper class; and this parameter is passed invisibly to
. There is nothing unusual about it — this is how all instance methods work. But as a result, the method of the wrapper
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
. 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.