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 3875236
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:14:36+00:00 2026-05-19T22:14:36+00:00

I am stuck up in a place. I am reading a flv file from

  • 0

I am stuck up in a place. I am reading a flv file from a URL. I am reading this to a Stream and then writing this Stream to a MemoryStream in a loop. When the code comes out of the loop, I am writing the whole MemoryStream to a ByteArray and then writing this ByteArray to a local file on my hard disk.

As this flv is too large, it takes a lot of time to process in the loop. I am thinking of reading the original large stream in MemoryStream in multiple threads. That means dividing the Stream in say 10 parts and writing these parts to MemoryStream in multiple threads. How do I do this?

I am attaching my piece of code.

//Get a data stream from the url
                WebRequest req = WebRequest.Create(url);
                WebResponse response = req.GetResponse();
                using (Stream stream = response.GetResponseStream())
                {
                    //Download in chuncks
                    byte[] buffer = new byte[1024];

                    //Get Total Size
                    int dataLength = (int)response.ContentLength;



                    //Download to memory
                    //Note: adjust the streams here to download directly to the hard drive
                    using (MemoryStream memStream = new MemoryStream())
                    {
                        while (true)
                        {
                            //Try to read the data
                            int bytesRead = stream.Read(buffer, 0, buffer.Length);

                            if (bytesRead == 0)
                            {
                                Application.DoEvents();
                                break;
                            }
                            else
                            {
                                //Write the downloaded data
                                memStream.Write(buffer, 0, bytesRead);
                            }
                        }

                        //Convert the downloaded stream to a byte array
                        byte[] downloadedData = memStream.ToArray();
                    }  


                }

Any help is appreciated
Thanks

  • 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-05-19T22:14:37+00:00Added an answer on May 19, 2026 at 10:14 pm

    You won’t be able to speed up the download by using multiple threads. The limiting factor here is not how fast your computer can process the data, but rather how fast the data comes from the server.

    Rather than try to speed this up using multiple threads, I would suggest that you create a WebClient rather than WebRequest. You can then call WebClient.DownloadDataAsync to download data into memory in the background, or call WebClient.DownloadFileAsync to download directly to a file.

    Neither one of those will make the download any faster, but they will prevent your user interface from being non-responsive during the download.

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

Sidebar

Related Questions

I'm trying to scrape content from a webpage. Currently I'm stuck at a place
I am putting together a dynamic photo gallery and getting stuck trying to place
Is there a good place to stick startup code for a NetBeans Platform app?
Been stuck on this for ages. Currently learning Django and done some bits on
Im stuck with this little project in C# but basically my problem is this:
After reading online about hash-bangs. Ive decided to stick with our current url structure.
I'm stuck with in a place, where I want to generate a xls report,
I'm currently stuck between a rock and a hard place. I need to identify
I have looked all of the place for this and I can't seem to
This is quite literally driving me bananas - I'm on holiday as from tomorrow

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.