Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MethodInvoker and passing Arguments

Posted on 2011-02-18
2
Medium Priority
?
4,529 Views
Last Modified: 2012-06-21
Probably another easy question, but I'm stumped.

So, if InvokeRequired is true then it invokes.  But the function has arguments.

Either way, if I pass them after AddressOf, the compiler complains.

If i dont pass them, vb.net has a problem, says I need to pass them.


Public Sub addscandata(ByVal target As String, ByVal port As Integer, ByVal stat As String)

        If Me.InvokeRequired Then
            Me.Invoke(New MethodInvoker(AddressOf addscandata()))
        Else

            rtb_scan_data.AppendText(stat & ":" & target & ":" & port)

        End If
    End Sub

Open in new window

0
Comment
Question by:highrate
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:highrate
ID: 34929666
Sorry, don't know how I added C# to the zone.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 34929749
Create a delegate with the same signature as your method and then use it along with an array of object to pass the parameters:
Public Delegate Sub ScanDataDelegate(ByVal target As String, ByVal port As Integer, ByVal stat As String)

    Public Sub addscandata(ByVal target As String, ByVal port As Integer, ByVal stat As String)
        If Me.InvokeRequired Then
            Me.Invoke(New ScanDataDelegate(AddressOf addscandata), New Object() {target, port, stat})
        Else
            rtb_scan_data.AppendText(stat & ":" & target & ":" & port)
        End If
    End Sub

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Simple Linear Regression
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question