Knight Chat X Posted March 20, 2004 Posted March 20, 2004 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 can't 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? Quote
Leaders dynamic_sysop Posted March 20, 2004 Leaders Posted March 20, 2004 MyMethod must be a Sub which has nothing between the ( ) you would need to handle any extra stuff inside the Sub. eg: 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] Quote
Knight Chat X Posted March 21, 2004 Author Posted March 21, 2004 MyMethod must be a Sub which has nothing between the ( ) you would need to handle any extra stuff inside the Sub. eg: 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 I'm 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? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.