Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I have a subroutine that looks like that
Function GetCodekeyFunction(ByVal realstring As String, ByVal en As String, ByVal encrpyed As String) As String
  'code here

End Function

and I want to call it from another thread
Dim threadd As New System.Threading.Thread(AddressOf GetCodekeyFunction("F", "F", "F"))

but it doesn't work!

How can I declare a thread that calls a sub or function with parameters??
Updated 18-Feb-11 7:48am

1 solution

One way is to use ParameterizedThreadStart.

Take a look at this[^] thread, or search the internet. Be careful with the MSDN pages that might be in the list of hits, since I believe the example they use to be incorrect.
Share this answer
Sergey Alexandrovich Kryukov 18-Feb-11 16:58pm    
Henry, did I tell you ParameterizedThreadStart is bad in principle, because of casting. There is much better solution: write a wrapper around thread and pass its instance method to the thread start. As instance method passes "this" as a hidden call parameter, the whole wrapper class instance is passed via "this", which is equivalent to passing unlimited number of parameters, even via synchronized properties, etc. No cast is required. I don't think I can write it in VB.NET though. I've a C# code though:
Henry Minute 18-Feb-11 20:51pm    
I'm not sure if you have mentioned this before, or not, SA, but I am very old and my memory ain't what it used to be. I'll take a look at your link though. :)
Henry Minute 18-Feb-11 20:54pm    
I've bookmarked that and will take a look later today. It's very late here and waaay past my bed-time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900