HTTP-Download (Multithreading)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VBTricks.de.vu Webmaster

    #1

    HTTP-Download (Multithreading)

    Hello,

    at the moment I'm not able to finish my program. That means, I have a
    problem I can't solve myself. Therefore I'm asking those who already
    worked with HttpWebRequest. .. and threads.

    I'm writing some kind of download-manager, which is able to download
    several files parallely. Therefore I've created a class implementing the
    download function and use four threads which use four instances of the
    class. This works fine, except the cancelling of downloads. After a
    download-thread has been cancelled, it is not able to download any files
    with this thread.

    How the program works:
    The source for the downloadclass I got from the .net-Documentation and
    enhanced in some points.
    The download form has arrays for the class-instances, boolvalues
    (instance busy or not) and threads (calling StartDownload-function of
    classes).
    A timer (timWatchTimer) cares for the single threads. If a thread is not
    busy anymore (boolvalue bThreadWorking) the next download is started for
    this thread (StartNextDownl oad).

    I removed all unnecessary code for a better overview. The sample project
    can be found at:
    http://vbtricks.vb.funpic.de/vbarchiv/dstest.zip.
    The sample has been written using SharpDevelop, but in the subfolder VS
    you find a VS-export of the project. The source does have comments but
    if there any questions, please don't hesitate to ask them. I'm really up
    to solve this problem as I want to finish my program.


    Please help me,

    Stefan
    --
    _______________ _______________ _____www.VBTric ks.de.vu
    the free resource for Visual Basic, Gambas and Pascal
    components, tips & complete projects

    www: http://www.VBTricks.de.vu
    mail: vbtricks <at> gmx <dot> net
    _______________ _______________ _______________ ________
  • Ken Tucker [MVP]

    #2
    Re: HTTP-Download (Multithreading )

    Hi,

    If you are using windows xp bits might be best way to go.

    http://msdn.microsoft.com/library/de...un02282003.asp

    Ken
    ---------------
    "VBTricks.d e.vu Webmaster" <nospam@thisser verdoesntexist. com> wrote in
    message news:uWG8UkxgFH A.1416@TK2MSFTN GP09.phx.gbl...
    Hello,

    at the moment I'm not able to finish my program. That means, I have a
    problem I can't solve myself. Therefore I'm asking those who already
    worked with HttpWebRequest. .. and threads.

    I'm writing some kind of download-manager, which is able to download
    several files parallely. Therefore I've created a class implementing the
    download function and use four threads which use four instances of the
    class. This works fine, except the cancelling of downloads. After a
    download-thread has been cancelled, it is not able to download any files
    with this thread.

    How the program works:
    The source for the downloadclass I got from the .net-Documentation and
    enhanced in some points.
    The download form has arrays for the class-instances, boolvalues
    (instance busy or not) and threads (calling StartDownload-function of
    classes).
    A timer (timWatchTimer) cares for the single threads. If a thread is not
    busy anymore (boolvalue bThreadWorking) the next download is started for
    this thread (StartNextDownl oad).

    I removed all unnecessary code for a better overview. The sample project
    can be found at:
    http://vbtricks.vb.funpic.de/vbarchiv/dstest.zip.
    The sample has been written using SharpDevelop, but in the subfolder VS
    you find a VS-export of the project. The source does have comments but
    if there any questions, please don't hesitate to ask them. I'm really up
    to solve this problem as I want to finish my program.


    Please help me,

    Stefan
    --
    _______________ _______________ _____www.VBTric ks.de.vu
    the free resource for Visual Basic, Gambas and Pascal
    components, tips & complete projects

    www: http://www.VBTricks.de.vu
    mail: vbtricks <at> gmx <dot> net
    _______________ _______________ _______________ ________


    Comment

    • Inge Henriksen

      #3
      Re: HTTP-Download (Multithreading )

      I wonder if you shouldnt read the data sent from the web server before
      closing down the connection. Like this I guess:

      Dim asynchronousInp utRead As IAsyncResult = _
      responseStream. BeginRead(myReq uestState.Buffe rRead, _
      0, 1024, _
      New AsyncCallback(A ddressOf ReadCallBack), _
      myRequestState)
      ' Now try and close
      FinishedProc(St atusCodes.iErro rOccurred, _
      ErrorCodes.iUse rCancelled)


      "VBTricks.d e.vu Webmaster" <nospam@thisser verdoesntexist. com> skrev i
      melding news:uWG8UkxgFH A.1416@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Hello,
      >
      > at the moment I'm not able to finish my program. That means, I have a
      > problem I can't solve myself. Therefore I'm asking those who already
      > worked with HttpWebRequest. .. and threads.
      >
      > I'm writing some kind of download-manager, which is able to download
      > several files parallely. Therefore I've created a class implementing the
      > download function and use four threads which use four instances of the
      > class. This works fine, except the cancelling of downloads. After a
      > download-thread has been cancelled, it is not able to download any files
      > with this thread.
      >
      > How the program works:
      > The source for the downloadclass I got from the .net-Documentation and
      > enhanced in some points.
      > The download form has arrays for the class-instances, boolvalues (instance
      > busy or not) and threads (calling StartDownload-function of classes).
      > A timer (timWatchTimer) cares for the single threads. If a thread is not
      > busy anymore (boolvalue bThreadWorking) the next download is started for
      > this thread (StartNextDownl oad).
      >
      > I removed all unnecessary code for a better overview. The sample project
      > can be found at:
      > http://vbtricks.vb.funpic.de/vbarchiv/dstest.zip.
      > The sample has been written using SharpDevelop, but in the subfolder VS
      > you find a VS-export of the project. The source does have comments but if
      > there any questions, please don't hesitate to ask them. I'm really up to
      > solve this problem as I want to finish my program.
      >
      >
      > Please help me,
      >
      > Stefan
      > --
      > _______________ _______________ _____www.VBTric ks.de.vu
      > the free resource for Visual Basic, Gambas and Pascal
      > components, tips & complete projects
      >
      > www: http://www.VBTricks.de.vu
      > mail: vbtricks <at> gmx <dot> net
      > _______________ _______________ _______________ ________[/color]



      Comment

      • Tom Shelton

        #4
        Re: HTTP-Download (Multithreading )

        On 2005-07-07, VBTricks.de.vu Webmaster <nospam@thisser verdoesntexist. com> wrote:[color=blue]
        > Hello,
        >
        > at the moment I'm not able to finish my program. That means, I have a
        > problem I can't solve myself. Therefore I'm asking those who already
        > worked with HttpWebRequest. .. and threads.
        >
        > I'm writing some kind of download-manager, which is able to download
        > several files parallely. Therefore I've created a class implementing the
        > download function and use four threads which use four instances of the
        > class. This works fine, except the cancelling of downloads. After a
        > download-thread has been cancelled, it is not able to download any files
        > with this thread.
        >
        > How the program works:
        > The source for the downloadclass I got from the .net-Documentation and
        > enhanced in some points.
        > The download form has arrays for the class-instances, boolvalues
        > (instance busy or not) and threads (calling StartDownload-function of
        > classes).
        > A timer (timWatchTimer) cares for the single threads. If a thread is not
        > busy anymore (boolvalue bThreadWorking) the next download is started for
        > this thread (StartNextDownl oad).
        >
        > I removed all unnecessary code for a better overview. The sample project
        > can be found at:
        > http://vbtricks.vb.funpic.de/vbarchiv/dstest.zip.
        > The sample has been written using SharpDevelop, but in the subfolder VS
        > you find a VS-export of the project. The source does have comments but
        > if there any questions, please don't hesitate to ask them. I'm really up
        > to solve this problem as I want to finish my program.
        >
        >
        > Please help me,
        >
        > Stefan[/color]

        If your on a 2K or higher system and don't need to support 9x, then I
        agree with Ken - use BITS. If you don't like the wrapper in the article
        he pointed out, I have one that I wrote in C# ages ago :) And, yes, the
        library does work with VB.NET. In fact, when I wrote it - I wrote the
        wrapper in C#, but wrote the test app in VB.NET to make sure it would
        work...


        Anyway, as for the threads... I haven't really looked at the code so
        I'm not sure what your doing here. I just wanted to interject my support
        of BITS :) I have downloaded the project, and if I get a moment, I'll
        see if I can see anything that strikes me as out of place :)

        --
        Tom Shelton [MVP]

        Comment

        • VBTricks.de.vu Webmaster

          #5
          Re: HTTP-Download (Multithreading )

          Hello,

          sorry for replying that late. The problem could be fixed by ensuring
          that the response-stream has been closed when the download is cancelled.


          Stefan

          --
          _______________ _______________ _____www.VBTric ks.de.vu
          the free resource for Visual Basic, Gambas and Pascal
          components, tips & complete projects

          www: http://www.VBTricks.de.vu
          mail: vbtricks <at> gmx <dot> net
          _______________ _______________ _______________ ________

          Comment

          Working...