Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
GeneralRe: Windows Media Player 11 Pin
henur12-Sep-07 4:19
henur12-Sep-07 4:19 
QuestionFindString Problem Pin
Xmen Real 12-Sep-07 1:12
professional Xmen Real 12-Sep-07 1:12 
AnswerRe: FindString Problem Pin
Luc Pattyn12-Sep-07 2:27
sitebuilderLuc Pattyn12-Sep-07 2:27 
GeneralRe: FindString Problem Pin
Xmen Real 12-Sep-07 3:58
professional Xmen Real 12-Sep-07 3:58 
GeneralRe: FindString Problem Pin
Luc Pattyn12-Sep-07 4:06
sitebuilderLuc Pattyn12-Sep-07 4:06 
QuestionSemi automatic forground video segmentation Pin
ptr_Electron12-Sep-07 0:48
ptr_Electron12-Sep-07 0:48 
AnswerRe: Semi automatic forground video segmentation Pin
Ed.Poore12-Sep-07 2:09
Ed.Poore12-Sep-07 2:09 
QuestionDownload multiple files? [modified] Pin
bug_aonz12-Sep-07 0:35
bug_aonz12-Sep-07 0:35 
- Could u share your ideas?

My intent is to download more than 100 files from web server. Assume that my web server is http://111,222,333,444/ and i have 100 files(with small size) named "A1","A2"..."A100" within Data folder likes

http://111.222.333.444/Data/A1 .

Which is the best way to download all of these files with highest connection speed?

Because of i applied WebRequest , WebResponse, and multi-threading(1 thread for 1 file),it has too long delay when connect to each file.Could u give me an adviced how to do this?

This is my sample code.

<br />
ArrayList filenameList=new ArrayList();<br />
filenameList.Add("http://111.222.333.444/Data/A1");<br />
filenameList.Add("http://111.222.333.444/Data/A2");<br />
filenameList.Add("http://111.222.333.444/Data/A3");<br />
...<br />
filenameList.Add("http://111.222.333.444/Data/A10000");<br />
<br />
for(int i=0;i<filenameList.Count;i++)<br />
{<br />
   Thread workThread=new Thread(new ParametrizeThreadStart(downloadMethod));<br />
   workThread.Start(filenameList[i]);<br />
}<br />
<br />
public void downloadMethod(object TargetUrl)<br />
{<br />
   string Target=TargetUrl as string<br />
   HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Target);<br />
   req.Timeout = 100000 * 3;<br />
   req.Proxy = new WebProxy(new Uri("http://localhost:3128"));<br />
   resp = (HttpWebResponse)req.GetResponse();<br />
   Stream stm = resp.GetResponseStream();<br />
   int ReadCount;<br />
   byte[] buffer = new byte[65535];<br />
   FileStream f = File.Open(SaveDirectory + "/" + filename, FileMode.Create<br />
                  , FileAccess.Write, FileShare.None);<br />
   if (stm.CanRead)<br />
   {<br />
     while ((int)(ReadCount = stm.Read(buffer, 0, buffer.Length)) > 0)<br />
     {<br />
         f.Write(buffer, 0, ReadCount); <br />
     }  <br />
   }<br />
   f.Flush();<br />
   f.Close();<br />
}<br />


Likes that,the main problem is "resp = (HttpWebResponse)req.GetResponse();" becuase it has too much delay time.

Can i use multi-threading like this? Are there better way?

Thank
=)



-- modified at 6:40 Wednesday 12th September, 2007
AnswerRe: Download multiple files? Pin
Mark Swaanenburg12-Sep-07 2:23
Mark Swaanenburg12-Sep-07 2:23 
AnswerRe: Download multiple files? Pin
Scott Dorman12-Sep-07 8:18
professionalScott Dorman12-Sep-07 8:18 
QuestionRe: Download multiple files? Pin
bug_aonz12-Sep-07 17:11
bug_aonz12-Sep-07 17:11 
AnswerRe: Download multiple files? Pin
Scott Dorman13-Sep-07 4:16
professionalScott Dorman13-Sep-07 4:16 
GeneralRe: Download multiple files? Pin
bug_aonz13-Sep-07 16:56
bug_aonz13-Sep-07 16:56 
QuestionHow to check in form2 if a button on form1 has been clicked Pin
Lucy12-Sep-07 0:20
Lucy12-Sep-07 0:20 
AnswerRe: How to check in form2 if a button on form1 has been clicked Pin
blackjack215012-Sep-07 0:33
blackjack215012-Sep-07 0:33 
GeneralRe: How to check in form2 if a button on form1 has been clicked Pin
Lucy12-Sep-07 0:54
Lucy12-Sep-07 0:54 
AnswerRe: How to check in form2 if a button on form1 has been clicked Pin
Malcolm Smart12-Sep-07 1:00
Malcolm Smart12-Sep-07 1:00 
AnswerRe: How to check in form2 if a button on form1 has been clicked Pin
Xmen Real 12-Sep-07 1:24
professional Xmen Real 12-Sep-07 1:24 
GeneralRe: How to check in form2 if a button on form1 has been clicked Pin
Lucy12-Sep-07 1:29
Lucy12-Sep-07 1:29 
GeneralRe: How to check in form2 if a button on form1 has been clicked Pin
Xmen Real 12-Sep-07 1:31
professional Xmen Real 12-Sep-07 1:31 
GeneralRe: How to check in form2 if a button on form1 has been clicked Pin
Lucy12-Sep-07 1:32
Lucy12-Sep-07 1:32 
GeneralRe: How to check in form2 if a button on form1 has been clicked Pin
Xmen Real 12-Sep-07 1:35
professional Xmen Real 12-Sep-07 1:35 
GeneralRe: How to check in form2 if a button on form1 has been clicked Pin
Pete O'Hanlon12-Sep-07 1:49
mvePete O'Hanlon12-Sep-07 1:49 
AnswerRe: How to check in form2 if a button on form1 has been clicked Pin
Anthony Mushrow12-Sep-07 2:02
professionalAnthony Mushrow12-Sep-07 2:02 
AnswerRe: How to check in form2 if a button on form1 has been clicked Pin
Paras Kaneriya12-Sep-07 22:32
Paras Kaneriya12-Sep-07 22:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.