Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:14:31+00:00 2026-06-07T04:14:31+00:00

I have user control which has method as this public void DownloadFileAsync() { ThreadStart

  • 0

I have user control which has method as this

    public void DownloadFileAsync()
    {
        ThreadStart thread = DownloadFile;
        Thread downloadThread = new Thread(thread);

        downloadThread.Start();
    }

In the form I have 4 user control as this. But when I call in the user controls DownloadFileAsync() for each control only two of them begin to download. After finishing one of them the next begins to downloads.

What is the problem and how I can download simultanesly each download?

Thank you for your attention.

    public void DownloadFile()
    {
        int byteRecieved = 0;
        byte[] bytes = new byte[_bufferSize];

        try
        {
            _webRequestDownloadFile = (HttpWebRequest)WebRequest.Create(_file.AddressURL);
            _webRequestDownloadFile.AddRange((int)_totalRecievedBytes);
            _webResponseDownloadFile = (HttpWebResponse)_webRequestDownloadFile.GetResponse();
            _fileSize = _webResponseDownloadFile.ContentLength;
            _streamFile = _webResponseDownloadFile.GetResponseStream();

            _streamLocalFile = new FileStream(_file.LocalDirectory, _totalRecievedBytes > 0 ? FileMode.Append : FileMode.Create);

            MessageBox.Show("Salam");
            _status = DownloadStatus.Inprogress;
            while ((byteRecieved = _streamFile.Read(bytes, 0, _bufferSize)) > 0 && _status == DownloadStatus.Inprogress)
            {

                _streamLocalFile.Write(bytes, 0, byteRecieved);

                _totalRecievedBytes += byteRecieved;

                if (_totalRecievedBytes >= _fileSize)
                {
                    argsCompleted.Status = DownloadStatus.Completed;
                    if (_fileDownloadCompleted != null)
                        _fileDownloadCompleted(_file, argsCompleted);
                    break;
                }

                argsProgress.UpdateEventArgument(DownloadStatus.Inprogress, _totalRecievedBytes);

                if (_fileDownloadProgress != null)
                    _fileDownloadProgress(_file, argsProgress);



            }
        }
        catch (Exception ex)
        {
            LogOperations.Log(ex.Message);
        }
        finally
        {
            _streamFile.Close();
            _streamFile.Close();
            _streamLocalFile.Close();
            _webResponseDownloadFile.Close();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:14:33+00:00Added an answer on June 7, 2026 at 4:14 am

    HTTP had a limit of 2 connections per Web Origin for a very long time, so people wouldn’t start too many downloads in parallel. This limit has been lifted, but many implementations including HttpWebRequest still implement it.

    From draft-ietf-httpbis-p1-messaging:

    Clients (including proxies) SHOULD limit the number of simultaneous
    connections that they maintain to a given server (including proxies).

    Previous revisions of HTTP gave a specific number of connections as a
    ceiling, but this was found to be impractical for many applications.
    As a result, this specification does not mandate a particular maximum
    number of connections, but instead encourages clients to be
    conservative when opening multiple connections.

    You can change the connection limit by setting the ConnectionLimit Property as follows:

    HttpWebRequest httpWebRequest = (HttpWebRequest)webRequest;
    httpWebRequest.ServicePoint.ConnectionLimit = 10;
    

    Don’t set the limit too high, so you don’t overload the server.

    Also, instead of using threads, you should consider using the WebClient Class and the asynchronous methods it provides (such as the DownloadDataAsync Method). See How can I programmatically remove the 2 connection limit in WebClient for how to change the connection limit here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user control which has a DateTimePicker overlaid with the single line
To explain confusing title, here is the deal. I have user control which has
I have a user control which displays the currently logged in user's name. I
I have a user control which uses objects as inner properties (some code is
I have a user control which is 2 RadCombos cascaded. I'm trying to add
I have developed a user-control which gets bound to an id-field and then enables
I have a wpf user control which exposes an IEnumerable ItemsSource DependencyProperty. I bind
I have a nested user control which appears on every single page. It contains
i have user control, which i render on several views. i want to show
I have a user control in silverlight which contains both XMAL and .cs file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.