How do I pass AddressOf method in a class for threading?

Knight Chat X

Member
Joined
Mar 20, 2004
Messages
22
Location
Tulsa, OK
The problem I have is I need to be able to pass the address of a method from another sub or function in a class.

The function below does not work as I cant declare as a method, "MyMethod" is a method elsewhere in the program which processes messages.

Public Function CreateListeningSocketThreadAndStartMessageProcessing(ByVal MyMethod As Method) As TcpListener

CreateListeningSocketThreadAndStartMessageProcessing = New Threading.Thread(AddressOf MyMethod) THIS DOES NOT WORK...

CreateListeningSocketThreadAndStartMessageProcessing.Start()

End Function

Is there solution?
 
MyMethod must be a Sub which has nothing between the ( )
you would need to handle any extra stuff inside the Sub. eg:
Code:
myThread = [COLOR=Blue]New[/COLOR] Threading.Thread([COLOR=Blue]AddressOf[/COLOR] MyMethod)

[COLOR=Green]/// then the Sub[/COLOR]
[COLOR=Blue]Public Sub[/COLOR] MyMethod()
[COLOR=Green]/// additional code here[/COLOR]
[COLOR=Blue]End Sub[/COLOR]
 
dynamic_sysop said:
MyMethod must be a Sub which has nothing between the ( )
you would need to handle any extra stuff inside the Sub. eg:
Code:
myThread = [COLOR=Blue]New[/COLOR] Threading.Thread([COLOR=Blue]AddressOf[/COLOR] MyMethod)

[COLOR=Green]/// then the Sub[/COLOR]
[COLOR=Blue]Public Sub[/COLOR] MyMethod()
[COLOR=Green]/// additional code here[/COLOR]
[COLOR=Blue]End Sub[/COLOR]

Thanks!

The problem lies here:
Public Function CreateListeningSocketThreadAndStartMessageProcessing(ByVal MyMethod As Method) As TcpListener

I already have a method without parameters for the AddressOf which would work, but the problem is with the MyMethod parameter declaration within the CreateListeningSocketThreadAndStartMessageProcessing function itself, see, there is no Dim Something As Method that I know of. The reason Im trying to use function in a class is so I can re-use the code for creating the thread within a class, yet still work with the message handler "MyMethod" linked to the thread on main form, this way I can ignore the code within the class and focus more on the events.

Public Function CreateListeningSocketThreadAndStartMessageProcessing(ByVal MyMethod As ???) As TcpListener

What would the parameter/argument syntax for the function be?
 
Back
Top