Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • Leaders
Posted

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]

Posted
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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...