Home > Net >  Multithreading issues
Multithreading issues

Time:04-12

A similar dynamic segmentation of IDM downloader to download

With c #

Assumptions have eight threads run at the same time, the file block to eight thread download (range), the eight thread download assume some download fast download some slow, when a thread download is completed, the thread is idle down

The idle thread will get other threads to download the remaining amount (has A threshold value, such as other documents also in the download as A thread block also need to download the surplus is greater than 200 k), fits the setting of threshold value after the idle thread will get half of the 200 k download, originally A thread end download subscript adjustment at the same time;

Q: what's the idle thread for other threads are downloading and threshold adjustment after the subscript, idle thread and continue to download?

 
HttpWebRequest request=(HttpWebRequest) WebRequest. Create (" https://download-cf.jetbrains.com/idea/ideaIU-2021.1.exe ");
Request. The Method="GET";
Request. UserAgent="Mozilla/5.0 (Windows NT 10.0; Win64. X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36 Edg/89.0.774.75 ";
Request. AllowAutoRedirect=false;
Request. The Timeout=10000;
Request. AllowAutoRedirect=true;
Request. AddRange (starIndex endIndex);
WebResponse wb=request. The method GetResponse ();
Using (Stream Stream=wb. GetResponseStream ())
{
Byte [] buffer=new byte [102400].
The string fileName=Path.Com bine (saveFilePath, ${I}. Fk1 - fk ");
Using (Stream fs=new FileStream (fileName, FileMode. Append, FileAccess. Write)) {
Long offset.
While (stream!=null & amp; & (offset=stream. Read (buffer, 0, buffer Length)) & gt; 0)
{
Fs. Write (buffer, 0, offset (int));
}
}
}
  •  Tags:  
  • C#
  • Related