VB.Net – Passing Multiple Parameters to a thread call without creating a class object

Ok, so in most cases when we need to make a threaded call we need to pass multiple parameters to the worker function. In VB.net by default it supports one parameter to be passed. But when we need to pass more than one parameter then we have to do a little trick.

Observe how the Object array is passed as a parameter using ByVal. When the array is populatd it will contain the refereces/address of the objects. So passing it by value actually passes the whole set of the references.
Thus this trick works even for ByRef variables/Reference variables/Pointer Variables.

Posted in


  1. Awesome! U shall go to heaven i swear!!


  2. Please note that if you have Option Strict On, this method will complain about Late Binding. It’s probably better to store the values in Private variables and then retrieve them later on:

    Private m_Value1 As Integer
    Private Sub Start()
    m_Value1 = 1
    m_Thread = New Thread(AddressOf Process)    
    End Sub
    Private Sub Process()
    End Sub


  3. Great!!
    I was looking for a trick for ByRef parameters.



Leave a Reply

Your email address will not be published. Required fields are marked *