Click here to Skip to main content
15,919,341 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I tried it with two download tasks. The tasks started at the same time but when first task was at GetResponseStream code line other task waited for first task to finish and continued when it was finished. What is the reason and the right code? My code is something like this=>
C#
public void Download1()
        {
            data1 = new byte[fp[0]];
            req1 = WebRequest.Create(url) as HttpWebRequest;
            MessageBox.Show("1");
            req1.AddRange(sp[0], fp[0] - 1);
            var asyncresult1 = req1.BeginGetResponse(ar =>
                {
                    using (var response = req1.EndGetResponse(ar))
                    using (var responseStream = response.GetResponseStream()) 
                    using (var reader = new StreamReader(responseStream))
                    {
                        string s = reader.ReadToEnd();
                        labeldurum.Text = s.Length.ToString();
                    }
                }, null);
            
        }
        HttpWebRequest req2;
        int totalbayt1 = 0, totalbayt2 = 0;
        public async void Download2()
        {
            
            data2 = new byte[fp[0] + 1];
            req2 = WebRequest.Create(url) as HttpWebRequest;
            MessageBox.Show("231");
            req2.AddRange(sp[1], filesize);
            var asyncresult = req2.BeginGetResponse(ar =>
            {
                using (var response = req2.EndGetResponse(ar))
                using (var responseStream = response.GetResponseStream())
                using (var reader = new StreamReader(responseStream))
                {
                    string s = reader.ReadToEnd();
                    labelhız.Text = s.Length.ToString();
                }

                }, null);
        }
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900