VB.NET and Threading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Johnson

    VB.NET and Threading

    Ill be the first to admit this is way beyond my current scope as a VB
    programmer but Im learning as I go.

    I playing with the new Threading features exposed by the 2.0 framework and
    have writting a very simple application that executes three sequential
    tasks, the second of which I send off on its on thread and it take a very
    long time, so the order of completion should be Task1, Task3, Task2.

    This all works, as astounding as I found that, and I am moving on to more
    complex tasks with Threading, which leads me to:

    When I send my second task on its on thread I use the following code:
    myPingThread = New System.Threadin g.Thread(Addres sOf myPingSub)
    myPingThread.St art()

    The problem here is that I cannot seem to pass an arguement to the myPingSub
    as "addressof operand must be the name of a method without parentheses".

    Can any of you more advanced VB guys assist me here in what Im overlooking?
    How, when setting a function off on its on thread, can I pass it a value?

    Thanks,
    chrisj


  • Kevin

    #2
    Re: VB.NET and Threading

    Make myPingSub be a member function in a class, and given the class
    data members. For instance:

    Module TestModule
    class MyPingClass
    Public data As String

    Public Sub myPingSub()
    System.Console. Writeline("You passed: " & data
    End Sub

    End Class

    Public Sub Main
    Dim mpc As New MyPingClass()

    mpc.data = "My data"

    Dim myPingThread As System.Threadin g.Thread = New
    System.Threadin g.Thread(Addres sOf mpc.myPingSub)
    myPingThread.St art()
    myPingThread.Jo in()

    End Sub
    End Module

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: VB.NET and Threading

      Chris,

      You know that using threading does as well mean that you use more processing
      time.

      I can only give you a benefit in the throughput time, however therefore you
      need parallel not depended processes.

      I thought you did not know that when I saw your message.

      Cor


      Comment

      • Chris Johnson

        #4
        Re: VB.NET and Threading

        For a brief process like I am currently executing I think your right, in
        that there isn't much gain in multithreading a simple ping application.

        But, I'm only using that as a learning block to figure out how to thread
        applications.

        My main goal is to modify a current personal project I have going that is a
        web image scraper using the new 2.0 classes that allow quick download of an
        image
        given its URL (I forget the class name). The problem I ran into was that
        whenever an image was being downloaded via my loop, the GUI became
        unresponsive because they are both on the same system thread, so I need a
        way to send the image download off to another thread.

        Hopefully by starting small like I am I can get the requisite knowledge
        about threading to then use in the aforementioned project and others in the
        future.

        Given the additional information above, if you have suggestions about
        possible alternatives, feel free to let me know!
        chrisj


        "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
        news:%23u46sJ%2 3BGHA.916@TK2MS FTNGP10.phx.gbl ...[color=blue]
        > Chris,
        >
        > You know that using threading does as well mean that you use more
        > processing time.
        >
        > I can only give you a benefit in the throughput time, however therefore
        > you need parallel not depended processes.
        >
        > I thought you did not know that when I saw your message.
        >
        > Cor
        >[/color]


        Comment

        • Cor Ligthert [MVP]

          #5
          Re: VB.NET and Threading

          Chris,

          You are probably number 10001 who is doing this.

          Have a look at the queue class to do this. As well know that HTTP has a
          limitied ammount of connections by default. (You can tweak this) (that
          scrapping you could do as well very quick in 1.x with
          webclient.downl oadfile).

          However have a look at that queu class that makes live in this a lot easier.



          I hope this helps,

          Cor



          Comment

          Working...