Results 1 to 4 of 4

Thread: Multithreading...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    15

    Multithreading...

    How do you pass multiple parameters to a Sub which has to be invoked?

    Again, I've only been coding for about 3 days so please speak as if your trying to teach a child to tie his shoe.

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Multithreading...

    The first argument to Invoke is the delegate and after that you just put all the arguments for the method being invoked, e.g. if you want to invoke this method:
    vb.net Code:
    1. Private Sub DoSomething(ByVal arg1 As Object, ByVal arg2 As Object, ByVal arg3 As Object)
    you would just do this:
    vb.net Code:
    1. Me.Invoke(New DoSomethingDelegate(AddressOf DoSomething), val1, val2, val3)
    When DoSomething is invoked, val1 will be passed to arg1, val2 to arg2 and val3 to arg3. You could also do it like this, and in fact had to before .NET 2.0:
    vb.net Code:
    1. Me.Invoke(New DoSomethingDelegate(AddressOf DoSomething), New Object() {val1, val2, val3})
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    15

    Re: Multithreading...

    What if there are no parameters you need to pass?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Multithreading...

    Quote Originally Posted by Phaaze View Post
    What if there are no parameters you need to pass?
    Then don't pass any. Invoke takes one or more arguments. The first is required and is the delegate and the rest are optional and are the arguments for the method being invoked. If the method being invoked has 1000 arguments then you pass 1001 arguments to Invoke. If the method being invoked has no arguments then you pass 1 argument to invoke.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width